lundi 2 mars 2015

Retrieve Facebook pages likes using custom login button

I have downloaded this sample project for custom login with Facebook:


FBLoginCustomUISample


and as a test I want to implement this method found on facebook sdk to retrive users pages likes:



/* make the API call */
[FBRequestConnection startWithGraphPath:@"/me/likes"
parameters:nil
HTTPMethod:@"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
NSLog(@"%@",result);
}];


I have copy-pasted it in the CustomLoginViewController.m like so:



- (IBAction)buttonTouched:(id)sender
{
// If the session state is any of the two "open" states when the button is clicked
if (FBSession.activeSession.state == FBSessionStateOpen
|| FBSession.activeSession.state == FBSessionStateOpenTokenExtended) {

// Close the session and remove the access token from the cache
// The session state handler (in the app delegate) will be called automatically
[FBSession.activeSession closeAndClearTokenInformation];

// If the session state is not any of the two "open" states when the button is clicked
} else {
// Open a session showing the user the login UI
// You must ALWAYS ask for public_profile permissions when opening a session
[FBSession openActiveSessionWithReadPermissions:@[@"public_profile"]
allowLoginUI:YES
completionHandler:
^(FBSession *session, FBSessionState state, NSError *error) {

// Retrieve the app delegate
AppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
// Call the app delegate's sessionStateChanged:state:error method to handle session state changes
[appDelegate sessionStateChanged:session state:state error:error];
[FBRequestConnection startWithGraphPath:@"/me/likes?limit=10"
parameters:nil
HTTPMethod:@"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
NSLog(@"%@",result);
}];
}];
}

}


And I get returned an empty data when I LogIn.


Thanks for your help and please bare with me as this is my first attempt to work with the ios sdk.


Aucun commentaire:

Enregistrer un commentaire