Posting Facebook likes through an iOS app

Discussion in 'iOS Programming' started by MacMan988, Apr 19, 2014.

  1. MacMan988 macrumors 6502a

    Joined:
    Jul 7, 2012
    #1
    Hi, I'm trying to implement a fb like function for my iOS app. The app should post a like to a Facebook page when tapped on a button.

    The problem is, that the code works well for urls such as www.macrumors.com but it produces an error (com.facebook.sdk error 5) when trying to post a like to a fb page. Below is the code I'm using.

    Code:
     if (FBSession.activeSession.isOpen) {
                
                NSString *urlToLikeFor = @"http://www.macrumors.com";
                
                NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                                        urlToLikeFor, @"object",
                                        nil
                                        ];
                /* make the API call */
                [FBRequestConnection startWithGraphPath:@"/me/og.likes"
                                             parameters:params
                                             HTTPMethod:@"POST"
                                      completionHandler:^(
                                                          FBRequestConnection *connection,
                                                          id result,
                                                          NSError *error
                                                          ) {
                                          if (error) {
                                              NSLog(@"Error with liking the page: %@", [error localizedDescription]);
                                          } else {
                                              NSLog(@"Successfully liked the page!");
                                          }
                                      }];
                
                
            } else {
                // The person has initiated a login, so call the openSession method
                // and show the login UX if necessary.
                
                [appDelegate openSessionWithAllowLoginUI:YES];
            }
     
  2. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #2
    From here (stack overflow)

     
  3. dotri84 macrumors newbie

    Joined:
    Jun 27, 2010
    #3
    You can overcome by using webview and put a facebook like button in it. Try to make it look like a button.
     

Share This Page