我正在嘗試在我的應用中獲取名稱,ID等的Facebook好友列表。在iOS中獲取Facebook好友列表
- (IBAction)onFBLogin:(id)sender {
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login
logInWithReadPermissions: @[@"public_profile", @"email", @"user_friends"]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(@"Process error");
} else if (result.isCancelled) {
NSLog(@"Cancelled");
} else {
NSLog(@"%@", result);
[self getFBEmailAddress];
}
}];
}
-(void)getFBEmailAddress{
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me"
parameters:@{@"fields": @"picture, email, friends"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSString *pictureURL = [NSString stringWithFormat:@"%@",[result objectForKey:@"picture"]];
mFBId = [NSString stringWithFormat:@"%@",[result objectForKey:@"id"]];
NSLog(@"My Profile : %@", result);
NSLog(@"email is %@", [result objectForKey:@"email"]);
[self getFBFriendList];
}
else{
NSLog(@"%@", [error localizedDescription]);
}
}];
}
-(void)getFBFriendList{
NSString* graphPat = [[NSString alloc] initWithFormat:@"%@/friends", mFBId];
FBSDKGraphRequest *requestFriends = [[FBSDKGraphRequest alloc]
initWithGraphPath:graphPat
parameters:@{@"fields": @"id, name"}
HTTPMethod:@"GET"];
[requestFriends startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
if (!error && result)
{
NSArray *allFriendsResultData = [result objectForKey:@"data"];
if ([allFriendsResultData count] > 0)
{
for (NSDictionary *friendObject in allFriendsResultData)
{
NSString *friendName = [friendObject objectForKey:@"name"];
NSString *friendID = [friendObject objectForKey:@"id"];
NSLog(@"%@ : %@", friendID, friendName);
}
}
}
}];}
我已經成功通過Facebook登錄並獲得我的個人資料。之後,我試圖通過朋友圖api獲得朋友列表。但那個時候,它只是說下面的朋友數。
friends = {
data = (
);
summary = {
"total_count" = 2;
};
};
id = 60XXXXXX1295X;
picture = {
data = {
"is_silhouette" = 0;
url = "https://scontent.xx.fbcdn.net/hprofile-xfa1/v/t1.0-1/p50x50/1..._501957533...";
};
};
如何獲取朋友列表的完整信息,如身份證,姓名等?如果有任何人已經實施,請幫助我。謝謝。