Reputation: 478
I'm using below code to get facebook friends list, and its working fine. But there is a need of friends profile picture too.
NSString *fbPermissions = @[ @"user_about_me",@"email",@"user_friends"];
NSString *apiIdKey = @"App_Key";
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
id options = @{
ACFacebookAppIdKey: apiIdKey,
ACFacebookPermissionsKey: fbPermissions,
ACFacebookAudienceKey: ACFacebookAudienceFriends,
};
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier: ACAccountTypeIdentifierFacebook];
[accountStore requestAccessToAccountsWithType:accountType options:options completion:^(BOOL granted, NSError *error)
{
if (granted == YES)
{
NSArray *arrayOfAccounts = [accountStore accountsWithAccountType:accountType];
ACAccount *tempAccount = [arrayOfAccounts lastObject];
NSString *string = [NSString stringWithFormat:@"https://graph.facebook.com/me/friends"];
NSURL *fbURL = [NSURL URLWithString:string];
SLRequest *fbRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:fbURL
parameters:nil];
[fbRequest setAccount:tempAccount];
[fbRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if (!error)
{
NSError *jsonError = nil;
NSDictionary *data = [NSJSONSerialization JSONObjectWithData:responseData
options:NSJSONReadingAllowFragments
error:&jsonError];
NSMutableArray *array = [data valueForKey:@"data"];
NSLog(@"Friends array:- %@",array);
}
else
{
[[[UIAlertView alloc]initWithTitle:@"Error"
message:[error description]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil] show];
}
}];
}
}];
To get profile picture I have changed request url with:-
NSString *string = [NSString stringWithFormat:@"https://graph.facebook.com/me/friends?fields=picture,name"];
I got following response :-
{
error = {
code = 2500;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
}
I'm not sure its access token expiration error because to revert back request Url to previous one, code works fine.
Upvotes: 1
Views: 682
Reputation: 478
Finally it worked with:-
NSString *string = [NSString stringWithFormat:@"https://graph.facebook.com/me/friends"];
NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/me/friends"];
SLRequest *fbRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET URL:requestURL parameters:@{@"fields":@"id,name,picture,first_name,last_name,gender"}];
Upvotes: 1