2

我在我的 iOS 应用上使用 facebook sdk 登录和分享故事。

在 Facebook 上分享故事功能正常,但今天无法正常工作。我不知道为什么它不起作用,因为没有与该功能相关的代码更改。

以下是请求 publish_actions 权限的代码。

// Request 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 publish
            } else {
            // Permission granted
            }
        } else {
            NSLog(@"DEBUG: error = %@", error);
            // There was an error, handle it
            // See https://developers.facebook.com/docs/ios/errors/
        }
}];

错误信息如下,

Domain=com.facebook.sdk Code=2 "The operation couldn’t be completed. com.facebook.sdk:ErrorReauthorizeFailedReasonSessionClosed"
UserInfo=0xXXXXXXXXX {
    com.facebook.sdk:ErrorLoginFailedReason=
        com.facebook.sdk:ErrorReauthorizeFailedReasonSessionClosed, 
    NSLocalizedFailureReason=
        com.facebook.sdk:ErrorReauthorizeFailedReasonSessionClosed, 
       com.facebook.sdk:ErrorSessionKey= ... >
}

如果有人知道这一点,请帮助我。

** Facebook SDK 版本为 3.18,publish_actions 项已在 developer.facebook.com 中获得批准

4

1 回答 1

0

您可以使用FBSDKAccessToken

 if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"]) {

            [self doShare];
        } else {
            FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
            [login logInWithPublishPermissions:@[@"publish_actions"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
                if (error) {
                    // Process error
                } else if (result.isCancelled) {
                    // Handle cancellations
                } else {
                    // If you ask for multiple permissions at once, you
                    // should check if specific permissions missing
                    if ([result.grantedPermissions containsObject:@"publish_actions"]) {
                        // Do work

                        [self doShare];

                    }
                }
            }];
        }

在哪里共享

-(无效)doShare{

NSString *url = [NSString stringWithFormat:@"http://example.com/locations/%d",1];
NSDictionary *properties = @{

                             @"your action" :url
                             };
[[[FBSDKGraphRequest alloc]
  initWithGraphPath:@"me/example-staging:something"
  parameters: properties
  HTTPMethod:@"POST"]
 startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
     if (!error) {
         // NSLog(@"Post id:%@", result[@"id"]);

     }
 }];
于 2015-05-27T09:26:39.150 回答