我正在尝试通过我的应用程序中的 Facebook 功能创建共享。
按照 facebook 开发人员网站上的教程,我设置了我的项目并且登录工作正常。
但是,我无法使请求更多权限起作用。我需要向用户询问 publish_actions 权限,以便能够代表他从我的应用中发布。
例如,我有以下活动会话:
2014-06-02 10:44:56.729 facebook[68183:60b] activeSession: , expireDate: 2014-07-28 14:50:04 +0000,refreshDate: 2014-05-30 11:03:01 +0000,尝试RefreshDate :0001-12-30 00:00:00 +0000,权限:(已安装,“public_profile”)>
我尝试分享的代码是:
[FBRequestConnection startWithGraphPath:@"me/permissions"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error){
NSDictionary *permissions= [(NSArray *)[result data] objectAtIndex:0];
if (![permissions objectForKey:@"publish_actions"]){
// Permission hasn't been granted, so ask for publish_actions
[FBSession.activeSession requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound){
// Permission not granted, tell the user we will not share to Facebook
NSLog(@"Permission not granted, we will not share to Facebook.");
} else {
// Permission granted, publish the OG story
[self requestWithGraphPath:@"me/feed" andParams:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"http://www.in.gr",@"url",@"messageTitle",@"Titleos",@"description",@"description", nil] andHttpMethod:@"POST"];
}
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(@"Encountered an error requesting permissions: %@", error.description);
}
}];
} else {
// Permissions present, publish the OG story
[self requestWithGraphPath:@"me/feed" andParams:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"http://www.in.gr",@"url",@"messageTitle",@"Titleos",@"description",@"description", nil] andHttpMethod:@"POST"];
}
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(@"Encountered an error checking permissions: %@", error.description);
}
}];
虽然我已经登录,但当我尝试请求附加权限时,它会再次要求我登录,而不是要求我批准附加权限。最重要的是,即使我再次登录,它也不会在所有 publish_actions 权限之后授予我。
如何成功请求发布所需的权限?