Search code examples
iphoneiosfacebookfacebook-likefacebook-opengraph

Is it possible for user of an ios app to like a URL on facebook using the facebook-sdk?


I am creating an iOS app where I want to allow the user to like a specific URL. I've tried to use the following code (as mentioned on the Facebook developers page) to like a specific url:

**- (IBAction)likeClicked:(UIButton *)sender {
    SLAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
    [FBSession setActiveSession:appDelegate.session];
    if (appDelegate.session.isOpen)
    {
        NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];
        action[@"object"] =  @"http://samples.ogp.me/226075010839791";



        [FBRequestConnection startForPostWithGraphPath:@"me/og.likes"
                                           graphObject:action
                                     completionHandler:^(FBRequestConnection *connection,
                                                         id result,
                                                         NSError *error) {
                                         NSLog(@"Error %@",error.localizedDescription);
                                         NSLog(@"result %@",result);
                                         // handle the result
                                     }];
    }

}**

But the above code only allows me to like the URL if I am authorized as an admin of that app on the facebook developer page.

If I am not an admin to the app with that specific app id , I get an error description as following:

Error The operation couldn’t be completed. (com.facebook.sdk error` 5.)

There are different solutions given on Stack Overflow for this but none of them seem to be working for me. I've checked for permissions and I have added the "publish_actions" permission to permissions list.

Is there another reason why i might be getting this error?

Is there another workaround using which i can like a specific URL on facebook?


Solution

  • There would be couple of places to check - Is your Facebook app under "sandbox mode", if it is you will have to turn it off once you are sure with your development.

    • If you have just created a FB graph action:
      • You are required to submit the action through the FB developer console and it usually takes couple days for them to approve, and once approved other users can start using the "like" action.
      • Until you get the action approved, only the App developers, testers and admins (on the FB developer site) for this particular app would be able to complete the action and see the results on their FB timeline.