-
-
Save kristersj/7809691 to your computer and use it in GitHub Desktop.
Ability to get more than just the name and id. - Get friends location, picture.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ACAccountStore *accountStore = [[ACAccountStore alloc] init]; | |
ACAccountType *facebookAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook]; | |
id options = @{ | |
ACFacebookAppIdKey: @"403376439767549", | |
ACFacebookPermissionsKey: @[ @"email", @"read_friendlists", @"friends_location"], | |
ACFacebookAudienceKey: ACFacebookAudienceFriends | |
}; | |
[accountStore requestAccessToAccountsWithType:facebookAccountType | |
options:options | |
completion:^(BOOL granted, NSError *error) { | |
if (granted) { | |
// Return back logined facebook Account | |
ACAccount *fbAccount = [[accountStore accountsWithAccountType:facebookAccountType] lastObject]; | |
// NSLog(@"%@", fbAccount); | |
// Do What you want... | |
// Request friend list | |
SLRequest *friendsListRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook | |
requestMethod:SLRequestMethodGET | |
URL: [[NSURL alloc] initWithString:@"https://graph.facebook.com/me/friends"] | |
parameters:@{@"fields":@"name,picture,location"}];]; | |
friendsListRequest.account = fbAccount; | |
[friendsListRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { | |
// Parse response JSON | |
NSError *jsonError = nil; | |
NSDictionary *data = [NSJSONSerialization JSONObjectWithData:responseData | |
options:NSJSONReadingAllowFragments | |
error:&jsonError]; | |
for (NSDictionary *friend in data[@"data"]) { | |
NSLog(@"name: %@", friend[@"name"]); | |
if (friend[@"location"]) { | |
NSDictionary *location = friend[@"location"]; | |
NSLog(@"location: %@", location[@"name"]); | |
} | |
//To get the picture check for the key "picture" and there will be a URL. | |
} | |
}]; | |
} | |
else { | |
NSLog(@"Not Granted %@", error); | |
} | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment