Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MacMan988

macrumors 6502a
Original poster
Jul 7, 2012
890
165
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 = @"https://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];
        }
 
You can overcome by using webview and put a facebook like button in it. Try to make it look like a button.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.