Search code examples
iosfacebook-likefacebook-ios-sdk

I got error message : {"error":{"message":"(#200) Permissions error","type":"OAuthException","code":200}} when i do a like action


I want to like a Facebook page, but I got this error:

{"error":{"message":"(#200) Permissions error","type":"OAuthException","code":200}}

As you can see on my code, permissions seems to be OK. Please notice that when I want to like a simple URL like www.google.com, it works!

I got this error only when i want to like a Facebook page.

Here is my code :

-(IBAction) buttonTestRecoFB
{
    NSArray *permissions = [[NSArray alloc] initWithObjects:
                            @"publish_actions",@"publish_stream",
                            nil];

    [FBSession.activeSession closeAndClearTokenInformation];

    [FBSession openActiveSessionWithPermissions:permissions allowLoginUI:YES
                              completionHandler:^(FBSession *session,
                                                  FBSessionState status,
                                                  NSError *error) {
                                  // session might now be open.
                                  [self sessionStateChanged:session state:status error:error];
                              }];
}

// FACEBOOK
//

- (void)sessionStateChanged:(FBSession *)session 
                      state:(FBSessionState) state
                      error:(NSError *)error
{
    switch (state) 
    {
        case FBSessionStateOpen: 
        {
            NSLog(@"FBSessionStateOpen");

            if (session.isOpen) 
            {
                FBRequest *me = [FBRequest requestForMe];

                [me startWithCompletionHandler: ^(FBRequestConnection *connection, 
                                                NSDictionary<FBGraphUser> *my,
                                                  NSError *error) {

                    NSLog(@"firtname = %@" , my.first_name);

                    /////////////////////////////////////////////////

                    NSString *theWholeUrl = [NSString stringWithFormat:@"https://graph.facebook.com/313449204401/likes?access_token=%@", session.accessToken];

                    NSLog(@"TheWholeUrl: %@", theWholeUrl);

                    NSURL *facebookUrl = [NSURL URLWithString:theWholeUrl];

                    NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:facebookUrl];
                    [req setHTTPMethod:@"POST"];

                    NSURLResponse *response;
                    NSError *err;
                    NSData *responseData = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&err];

                     NSString *content = [NSString stringWithUTF8String:[responseData bytes]];

                    NSLog(@"responseData: %@", content);
                    /////////////////////////////////////////////////                  
                }];
            }
        }

Solution

  • It's not possible to apply 'like' actions programmatically to Facebook pages. This is stated in the documentation:

    For Facebook Pages or websites that do not integrate with Facebook Authentication, developers should continue to use the Like button social plugin.