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.
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];
}