简体   繁体   中英

Error code 5 when publishing Facebook Open-Graph story through iOS?

I have been trying to publish a FB Opengraph story through xcode and havent been able to do so yet.

The url is a static url, with all the meta tags set in the html file itself.

 NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];

  action[@"testaction"] = @"http://myfbapp.com/fbobject.html";

[FBRequestConnection startForPostWithGraphPath:@"me/myfbapp:publish"
                                           graphObject:action
                                     completionHandler:
         ^(FBRequestConnection *connection, id result, NSError *error) {
}];

The code has been taken straight from the facebook app itself.

Thanks for any help!

Before calling startForPostWithGraphPath,

make sure the session is open:

NSLog(@"activeSession isOpen: %d", [[FBSession activeSession] isOpen]);

make sure the session has 'publish_actions' permissions:

NSLog(@"session perms: %@", [[FBSession activeSession] permissions]);

if not,

if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) {

then ask for permission:

if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) {
                defaultAudience:FBSessionDefaultAudienceFriends
                completionHandler:^(FBSession *session, NSError *error) {

The problem was that the action had not been reviewed by FB and was in test mode. The account I was trying to post with was not the developer account linked with the FB App and therefore I was unable to post the action.

Once I logged in with my dev account, it was working fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM