[英]Fetch Facebook logged-in user's Interest using Facebook iOS SDK API v2.4
[英]Facebook iOS SDK - get friends list in Graph API v2.4
我使用下面的代码来获取使用app的Facebook好友
// Issue a Facebook Graph API request to get your user's friend list
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:@"/{friendlist-id}"
parameters:nil
HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
// Handle the result
}];
但我得到了以下回复。
{
data = (
);
summary = {
"total_count" = 279;
};
}
我如何获得fbID,就像我们使用FBRequest获取最后一个api版本一样。
注意我使用的是最新的FB SDK。
谢谢。
根据新的API版本,它不可能获得FriendList或EmailId of Friends,但是如果你想要show FriendList使用Facebook的TaggableFriend功能。这个Taggable API需要来自Facebook的批准,这个API返回id,朋友的名字,个人资料图片URL。但是我不是FacebookId它的ID for wall.This唯一的方式来获取朋友。但如果你使用我/朋友它返回朋友和朋友的总数app用户的列表。 由于您没有应用程序用户,因此只显示总朋友数。要实现此功能,您需要使用管理员帐户(创建Facebook ID的帐户)登录,您必须实现分页概念。
使用此Code Spinnet:“/ me /taggable_friends?fields = id,name,picture.type (large)。
你可以得到朋友列表和许多其他详细信息如下:
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#import <FBSDKShareKit/FBSDKShareKit.h>
自定义Facebook按钮单击:
- (IBAction)facebook_click:(id)sender
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"public_profile", @"email", @"user_friends"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error)
{
// Process error
NSLog(@"error is :%@",error);
}
else if (result.isCancelled)
{
// Handle cancellations
NSLog(@"error is :%@",error);
}
else
{
if ([result.grantedPermissions containsObject:@"email"])
{
NSLog(@"Login successfull");
[self fetchUserInfo];
[login logOut];
}
}
}];
}
请求回复:
-(void)fetchUserInfo
{
if ([FBSDKAccessToken currentAccessToken])
{
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id,name,link,first_name, last_name, picture.type(large), email, birthday,friends,gender,age_range,cover"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error)
{
//NSLog(@"result is :%@",result);
NSLog(@"User ID : %@",[result valueForKey:@"id"]);
NSLog(@"User Name : %@",[result valueForKey:@"name"]);
NSLog(@"User First Name :%@",[result valueForKey:@"first_name"]);
NSLog(@"User Last Name :%@",[result valueForKey:@"last_name"]);
NSLog(@"USER Email is :%@",[result valueForKey:@"email"]);
NSLog(@"User fb_Link : %@",[result valueForKey:@"link"]);
NSLog(@"User Birthday : %@",[result valueForKey:@"birthday"]);
NSLog(@"FB Profile Photo Link :%@",[[[result valueForKey:@"picture"]objectForKey:@"data"]objectForKey:@"url"]);
NSLog(@"User total friends : %@",[[[result valueForKey:@"friends"]objectForKey:@"summary"]valueForKey:@"total_count"]);
NSLog(@"User Gender : %@",[result valueForKey:@"gender"]);
NSLog(@"User age_range : %@",[[result valueForKey:@"age_range"]objectForKey:@"min"]);
NSLog(@"User cover Photo Link : %@",[[result valueForKey:@"cover"]objectForKey:@"source"]);
//Friend List ID And Name
NSArray * allKeys = [[result valueForKey:@"friends"]objectForKey:@"data"];
fb_friend_Name = [[NSMutableArray alloc]init];
fb_friend_id = [[NSMutableArray alloc]init];
for (int i=0; i<[allKeys count]; i++)
{
[fb_friend_Name addObject:[[[[result valueForKey:@"friends"]objectForKey:@"data"] objectAtIndex:i] valueForKey:@"name"]];
[fb_friend_id addObject:[[[[result valueForKey:@"friends"]objectForKey:@"data"] objectAtIndex:i] valueForKey:@"id"]];
}
NSLog(@"Friends ID : %@",fb_friend_id);
NSLog(@"Friends Name : %@",fb_friend_Name);
}
}];
}
}
您可以使用此API获取朋友资料Pic。
NSString *str = [NSString stringWithFormat:@"http://graph.facebook.com/%@/picture?type=large",friend_id];
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:str]];
UIImage *profilePic = [UIImage imageWithData:imageData];
注意:它只会显示下载您的应用程序的好友列表。 不是你朋友的所有朋友。 根据新的API版本,它无法获得FriendList或FriendsId of Friends
您必须在登录时添加user_friends
权限
具有user_friends
权限的用户访问令牌需要查看该人员的任何朋友列表。
你只能得到安装相同应用的朋友,
只有安装此应用程序的朋友才能在API v2.0及更高版本中返回。 摘要中的total_count表示朋友的总数,包括尚未安装该应用的朋友。
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:@"me/friends"
parameters:nil
HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
// Handle the result
}];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.