Facebook publish_actions permission only working for admin account

699 views Asked by At

I am having some issues with the facebook sdk for iOS for publishing a status to facebook. I have turned on the "Do you want to make this app and all its live features available to the general public?" toggle in the dashboard. I am able to log into the admin account and publish the status update, but when I log in as another user I get the following error:

    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"
)>}

Here's the code that I am using to get permissions:

    - (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);
                     }
                 }
             }];

    }
}

And here's the code that I use to post the status:

    -(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"];
                          }];


}

Any help would be greatly appreciated. Thanks

0

There are 0 answers