Facebook publish_actions权限仅适用于管理员帐户

时间:2014-11-24 16:55:50

标签: ios facebook sdk publish-actions

我在facebook的sdk上遇到一些问题,用于向facebook发布状态。我打开了#34;你想让这个应用程序及其所有实时功能向公众开放吗?"在仪表板中切换。我能够登录管理员帐户并发布状态更新,但当我以其他用户身份登录时,我收到以下错误:

    Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0xa5b9de0 {com.facebook.sdk:HTTPStatusCode=403, com.facebook.sdk:ParsedJSONResponseKey={
    body =     {
        error =         {
            code = 200;
            message = "(#200) The user hasn't authorized the application to perform this action";
            type = OAuthException;
        };
    };
    code = 403;
    headers =     (
                {
            name = Expires;
            value = "Sat, 01 Jan 2000 00:00:00 GMT";
        },
                {
            name = "Cache-Control";
            value = "no-store";
        },
                {
            name = "Access-Control-Allow-Origin";
            value = "*";
        },
                {
            name = Pragma;
            value = "no-cache";
        },
                {
            name = "Content-Type";
            value = "text/javascript; charset=UTF-8";
        },
                {
            name = "Facebook-API-Version";
            value = "v2.2";
        },
                {
            name = "WWW-Authenticate";
            value = "OAuth \"Facebook Platform\" \"insufficient_scope\" \"(#200) The user hasn't authorized the application to perform this action\"";
        }
    );
}
    com.facebook.sdk:ErrorSessionKey=<FBSession: 0xa670520, state: FBSessionStateOpen, loginHandler: 0xa573850, appID: %$#%#%#$%#$%#$%, urlSchemeSuffix: free, tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0xa577b60>, expirationDate: 2015-01-23 16:13:18 +0000, refreshDate: 2014-11-24 16:43:00 +0000, attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(
    "public_profile"
)>}

这是我用来获取权限的代码:

    - (void)facebookCheckIn {
    NSArray *permissions =[NSArray arrayWithObjects:@"publish_actions", nil];
       if ([[FBSession activeSession]isOpen]) {
           /*
             * if the current session has no publish permission we need to reauthorize
             */
            if ([[[FBSession activeSession]permissions]indexOfObject:@"publish_actions"] == NSNotFound) {
               [[FBSession activeSession] requestNewPublishPermissions:permissions
                                                       defaultAudience:FBSessionDefaultAudienceFriends
                                                      completionHandler:^(FBSession *session,NSError *error){
                                                          [self showCustomMessage];
                                                      }];
            }
            else{
                [self showCustomMessage];
            }
        }else{
            /*
             * open a new session with publish permission
             */

            NSArray *requestPermission = @[@"publish_actions"];
            // Open session with public_profile
            [FBSession openActiveSessionWithPublishPermissions:requestPermission defaultAudience:FBSessionDefaultAudienceEveryone allowLoginUI:YES
                                             completionHandler:
             ^(FBSession *session, FBSessionState state, NSError *error) {
                 if (!error){
                     // If the session was opened successfully
                     if (state == FBSessionStateOpen){
                         // Your code here
                         [self showCustomMessage];

                     } else {
                         // There was an error, handle it
                         NSLog(@" error on opening session = %@",error);
                     }
                 }
             }];

    }
}

以下是我用来发布状态的代码:

    -(void)postToFacebook{
    NSLog(@"post to facebook");


    NSMutableDictionary<FBGraphObject> *place = [FBGraphObject graphObject];
    place[@"place"] = @"1342352523525"; // food Place id
    place[@"message"] = facebook_message;
    [FBRequestConnection startWithGraphPath:@"me/feed"
                                 parameters:place
                                 HTTPMethod:@"POST"
                          completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                              //verify result
                              NSLog(@"result: %@ %@", result,error.description);
                              if(error) {
                                  NSLog(@"Error FOR PLACE: %@", error.description);
                                  if ([error.description rangeOfString:@"506"].location != NSNotFound ) {
                                      [self showAnimatedMessage:@"You have already checked in using Facebook"];
                                  }
                                   else if([error.description rangeOfString:@"-1009"].location != NSNotFound )
                                  {
                                       [self showAnimatedMessage:@"The Internet connection appears to be offline."];
                                  }
                                  else if ([error.description rangeOfString:@"code = 1;"].location != NSNotFound ) {
                                      [self showAnimatedMessage:@"An Error Occured, please try again later."];
                                  }
                                  else
                                   {
                                       [self showAnimatedMessage:@"The user hasn't authorized the application to perform this action, need publish_actions permission?"];
                                   }
                               }
                              else {
                                   [self showAnimatedMessage:@"Successfully checked in with Facebook!"];
                                   NSLog(@"Status update submitted!");
                               }
                             // [self showAnimatedMessage:@"done"];
                          }];


}

非常感谢任何帮助。感谢

0 个答案:

没有答案