iOS 如何使用 FBSDK 获取 Facebook 好友列表?
How to get Facebook friends list using FBSDK for iOS?
我想在我的应用程序中从 facebook 获取好友列表。我能够正确获取 total_friends
,但结果中没有出现好友列表。
我当前的代码不起作用:
代码:
NSMutableString *facebookRequest = [NSMutableString new];
[facebookRequest appendString:@"/me/friends"];
[facebookRequest appendString:@"?limit=100"];
NSDictionary *friendParams = @{@"fields" : @"name"};
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"/me/friends"
parameters:friendParams
HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
//my code here
}
输出:
{
data = (
);
summary = {
"total_count" = 661;
};
}
我正在使用 Xcode 7.1
从 v2.0 开始 /me/friends
只会 return 正在使用您的应用程序的朋友。
因此,在您的情况下,您在 developer.facebook.com 中创建的应用程序未被您的任何朋友授权或使用
此外,您还必须请求每个用户user_friends
的许可
我使用了类似的方法,但我的代码在 swift 中。你的朋友列表是他们的,但你没有得到你必须创建一个数组的名字。并将您朋友的所有结果放入该数组。并显示在任何你想显示的地方。
这是 swift 中 Facebook 好友的代码:
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me/friends", parameters: ["fields": "id,name,picture"])
graphRequest.startWithCompletionHandler( { (connection, result, error) -> Void in
if ((error) != nil)
{
print("Error: \(error)")
return
}
else
{
let friends = result.valueForKey("data") as! NSArray
var count = 1
if let array = friends as? [NSDictionary] {
for friend : NSDictionary in array {
let name = friend.valueForKey("name") as! String
frindsFromGlobal.append(name)
count++
}
}
}
我想在我的应用程序中从 facebook 获取好友列表。我能够正确获取 total_friends
,但结果中没有出现好友列表。
我当前的代码不起作用:
代码:
NSMutableString *facebookRequest = [NSMutableString new];
[facebookRequest appendString:@"/me/friends"];
[facebookRequest appendString:@"?limit=100"];
NSDictionary *friendParams = @{@"fields" : @"name"};
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"/me/friends"
parameters:friendParams
HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
//my code here
}
输出:
{
data = (
);
summary = {
"total_count" = 661;
};
}
我正在使用 Xcode 7.1
从 v2.0 开始 /me/friends
只会 return 正在使用您的应用程序的朋友。
因此,在您的情况下,您在 developer.facebook.com 中创建的应用程序未被您的任何朋友授权或使用
此外,您还必须请求每个用户user_friends
的许可
我使用了类似的方法,但我的代码在 swift 中。你的朋友列表是他们的,但你没有得到你必须创建一个数组的名字。并将您朋友的所有结果放入该数组。并显示在任何你想显示的地方。
这是 swift 中 Facebook 好友的代码:
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me/friends", parameters: ["fields": "id,name,picture"])
graphRequest.startWithCompletionHandler( { (connection, result, error) -> Void in
if ((error) != nil)
{
print("Error: \(error)")
return
}
else
{
let friends = result.valueForKey("data") as! NSArray
var count = 1
if let array = friends as? [NSDictionary] {
for friend : NSDictionary in array {
let name = friend.valueForKey("name") as! String
frindsFromGlobal.append(name)
count++
}
}
}