openActiveSessionWithPublishPermissions / requestNewPublishPermissions publish_actions 未添加权限
openActiveSessionWithPublishPermissions / requestNewPublishPermissions publish_actions not adding permission
使用 SDK 3.22.0.
if (FBSession.activeSession.isOpen) {
[FBSession.activeSession
requestNewPublishPermissions:@[@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
NSLog(@"error = %@", error);
NSLog(@"session open = %d", session.isOpen);
NSLog(@"session.permissions = %@", session.permissions);
NSLog(@"session.accessTokenData.declinedPermissions = %@", session.accessTokenData.declinedPermissions);
}];
}
else {
[FBSession
openActiveSessionWithPublishPermissions:@[@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
NSLog(@"error = %@", error);
NSLog(@"session open = %d", session.isOpen);
NSLog(@"status = %lu", status);
NSLog(@"session.permissions = %@", session.permissions);
NSLog(@"session.accessTokenData.declinedPermissions = %@", session.accessTokenData.declinedPermissions);
}];
}
我正在测试一个没有发布权限并且也从未拒绝过的用户。在此帐户的 FB 应用程序设置中,应用程序可见性设置为 "Friends" 并且发布权限甚至不在设置列表中,因为它们是其他 users/apps.
在这两种代码情况下,FB 应用程序都会立即打开 returns 我的应用程序,无需请求权限。 declinedPermissions
的响应是一个包含 publish_actions
.
的数组
我的预期是 FB 应用会要求用户批准发布。
我收到了多个用户的报告,他们遇到了同样的问题 - 无法添加发布权限,但有些人能够获得权限。
要补充的一件事是,在将应用程序提交给测试组以外的用户进行 FB 批准之前,我遇到了同样的问题,但是当应用程序获得批准后,它开始为这些用户工作。现在看来,即使应用已获得批准,问题仍然存在,只是针对随机用户。
我请求权限的方式有问题吗?
我对这种方法也有类似的问题。我最终以一整套权限(读和写)打开了会话,它解决了我的问题。
-(void)requestPublishPermissionsWithCompletion:(FBHandlerComp)completion{
if (self.session.isOpen && [self.session.permissions containsObject:@"publish_actions"]){
//we have an open session and all neceassarry pemissions
completion(true,nil);
}else{
//something in missing, to account to all diffrent scenarios (missing persmission, expired tokens, changes in user sessting etc..), we reinisilise the session and request permissions
//for publish permissions we need to ask for the whole set( read& publish)
NSMutableArray *permissions = [NSMutableArray arrayWithArray:self.writePersmissions];
[permissions addObjectsFromArray:self.readPersmissions];
self.session = [[FBSession activeSession]initWithAppID:nil permissions:permissions defaultAudience:FBSessionDefaultAudienceFriends urlSchemeSuffix:nil tokenCacheStrategy:nil];
[self openFacebookSessionWithCompleteion:^(BOOL result, NSError *error) {
if (result) {
completion(true,nil);
}else{
if (LOGGING_IS_ON) DebugLog(@"could not get publish permissions- could not open session %@",error);
completion(false,nil);
}
}];
}
}
看起来这样有效:
- (BOOL)hasWritePermissions {
if (!FBSession.activeSession.isOpen) return NO;
return [FBSession.activeSession.permissions indexOfObject:@[@"publish_actions"]] != NSNotFound;
}
- (void)requestWritePermissions:(void(^)(BOOL status, NSError *error))callback {
if (self.hasWritePermissions) {
callback(YES, nil);
return;
}
if (FBSession.activeSession.isOpen) {
[FBSession.activeSession
requestNewPublishPermissions:@[@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
NSLog(@"error = %@", error);
NSLog(@"session open = %d", session.isOpen);
NSLog(@"session.permissions = %@", session.permissions);
NSLog(@"session.accessTokenData.declinedPermissions = %@", session.accessTokenData.declinedPermissions);
if (self.hasWritePermissions) {
callback(YES, nil);
}
else {
callback(NO, error);
}
}];
}
else {
[FBSession
openActiveSessionWithPublishPermissions:@[@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
NSLog(@"error = %@", error);
NSLog(@"session open = %d", session.isOpen);
NSLog(@"status = %u", status);
NSLog(@"session.permissions = %@", session.permissions);
NSLog(@"session.accessTokenData.declinedPermissions = %@", session.accessTokenData.declinedPermissions);
[self requestWritePermissions:callback]; // this time, with an open session
}];
}
}
如果没有会话,我 运行 openActiveSessionWithPublishPermissions
然后 运行 再次 requestNewPublishPermissions
。
问题是 openActiveSessionWithPublishPermissions
甚至没有去 Facebook 应用程序获取更多权限就触发了回调(看起来像 FB 错误,会报告),但这种方法似乎可以解决它。
我发现的另一个问题是 session.permissions 并不总是反映 Facebook 上的权限。我发现确保拥有最新权限的唯一方法是发出 API 请求:
[FBRequestConnection startWithGraphPath:@"/me/permissions" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
并检查 result.data 数组的 granted/declined 权限。
使用 SDK 3.22.0.
if (FBSession.activeSession.isOpen) {
[FBSession.activeSession
requestNewPublishPermissions:@[@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
NSLog(@"error = %@", error);
NSLog(@"session open = %d", session.isOpen);
NSLog(@"session.permissions = %@", session.permissions);
NSLog(@"session.accessTokenData.declinedPermissions = %@", session.accessTokenData.declinedPermissions);
}];
}
else {
[FBSession
openActiveSessionWithPublishPermissions:@[@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
NSLog(@"error = %@", error);
NSLog(@"session open = %d", session.isOpen);
NSLog(@"status = %lu", status);
NSLog(@"session.permissions = %@", session.permissions);
NSLog(@"session.accessTokenData.declinedPermissions = %@", session.accessTokenData.declinedPermissions);
}];
}
我正在测试一个没有发布权限并且也从未拒绝过的用户。在此帐户的 FB 应用程序设置中,应用程序可见性设置为 "Friends" 并且发布权限甚至不在设置列表中,因为它们是其他 users/apps.
在这两种代码情况下,FB 应用程序都会立即打开 returns 我的应用程序,无需请求权限。 declinedPermissions
的响应是一个包含 publish_actions
.
我的预期是 FB 应用会要求用户批准发布。
我收到了多个用户的报告,他们遇到了同样的问题 - 无法添加发布权限,但有些人能够获得权限。
要补充的一件事是,在将应用程序提交给测试组以外的用户进行 FB 批准之前,我遇到了同样的问题,但是当应用程序获得批准后,它开始为这些用户工作。现在看来,即使应用已获得批准,问题仍然存在,只是针对随机用户。
我请求权限的方式有问题吗?
我对这种方法也有类似的问题。我最终以一整套权限(读和写)打开了会话,它解决了我的问题。
-(void)requestPublishPermissionsWithCompletion:(FBHandlerComp)completion{
if (self.session.isOpen && [self.session.permissions containsObject:@"publish_actions"]){
//we have an open session and all neceassarry pemissions
completion(true,nil);
}else{
//something in missing, to account to all diffrent scenarios (missing persmission, expired tokens, changes in user sessting etc..), we reinisilise the session and request permissions
//for publish permissions we need to ask for the whole set( read& publish)
NSMutableArray *permissions = [NSMutableArray arrayWithArray:self.writePersmissions];
[permissions addObjectsFromArray:self.readPersmissions];
self.session = [[FBSession activeSession]initWithAppID:nil permissions:permissions defaultAudience:FBSessionDefaultAudienceFriends urlSchemeSuffix:nil tokenCacheStrategy:nil];
[self openFacebookSessionWithCompleteion:^(BOOL result, NSError *error) {
if (result) {
completion(true,nil);
}else{
if (LOGGING_IS_ON) DebugLog(@"could not get publish permissions- could not open session %@",error);
completion(false,nil);
}
}];
}
}
看起来这样有效:
- (BOOL)hasWritePermissions {
if (!FBSession.activeSession.isOpen) return NO;
return [FBSession.activeSession.permissions indexOfObject:@[@"publish_actions"]] != NSNotFound;
}
- (void)requestWritePermissions:(void(^)(BOOL status, NSError *error))callback {
if (self.hasWritePermissions) {
callback(YES, nil);
return;
}
if (FBSession.activeSession.isOpen) {
[FBSession.activeSession
requestNewPublishPermissions:@[@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
NSLog(@"error = %@", error);
NSLog(@"session open = %d", session.isOpen);
NSLog(@"session.permissions = %@", session.permissions);
NSLog(@"session.accessTokenData.declinedPermissions = %@", session.accessTokenData.declinedPermissions);
if (self.hasWritePermissions) {
callback(YES, nil);
}
else {
callback(NO, error);
}
}];
}
else {
[FBSession
openActiveSessionWithPublishPermissions:@[@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
NSLog(@"error = %@", error);
NSLog(@"session open = %d", session.isOpen);
NSLog(@"status = %u", status);
NSLog(@"session.permissions = %@", session.permissions);
NSLog(@"session.accessTokenData.declinedPermissions = %@", session.accessTokenData.declinedPermissions);
[self requestWritePermissions:callback]; // this time, with an open session
}];
}
}
如果没有会话,我 运行 openActiveSessionWithPublishPermissions
然后 运行 再次 requestNewPublishPermissions
。
问题是 openActiveSessionWithPublishPermissions
甚至没有去 Facebook 应用程序获取更多权限就触发了回调(看起来像 FB 错误,会报告),但这种方法似乎可以解决它。
我发现的另一个问题是 session.permissions 并不总是反映 Facebook 上的权限。我发现确保拥有最新权限的唯一方法是发出 API 请求:
[FBRequestConnection startWithGraphPath:@"/me/permissions" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
并检查 result.data 数组的 granted/declined 权限。