我正在使用社交框架检索Facebook好友列表。请看下面的代码,告诉我我在做什么,但它只给了我很少的朋友。我检查了两个帐户,一个帐户有300个,它只返回一个,一个有50个,它只返回我3.我也点击了下一页,但那是空的。
NSArray *accounts = [_accountStore accountsWithAccountType:FBaccountType];
//it will always be the last object with single sign on
_facebookAccount = [accounts lastObject];
ACAccountCredential *facebookCredential = [_facebookAccount credential];
NSString *accessToken = [facebookCredential oauthToken];
NSLog(@"Facebook Access Token: %@", accessToken);
_facebookAccount = [accounts lastObject];
_facebookToken = [facebookCredential oauthToken];
// _facebookToken = _facebookAccount.credential.oauthToken;
NSLog(@"facebook account =%@",_facebookAccount);
// Request friend list
NSDictionary *param=[NSDictionary dictionaryWithObjectsAndKeys:@"picture,id,name,link,gender,last_name,first_name",@"fields", nil];
SLRequest *friendsListRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL: [[NSURL alloc] initWithString:@"https://graph.facebook.com/me/friends"] parameters:param];
friendsListRequest.account = _facebookAccount;
[friendsListRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
// Parse response JSON
NSError *jsonError = nil;
NSDictionary *data = [NSJSONSerialization JSONObjectWithData:responseData
options:NSJSONReadingAllowFragments
error:&jsonError];
NSMutableArray * fbFriends=[[NSMutableArray alloc] init];
for (NSDictionary *friend in data[@"data"]) {
NSLog(@"name: %@", friend[@"name"]);
[fbFriends addObject:friend];
}
[[NSUserDefaults standardUserDefaults] setObject:fbFriends forKey:@"FBFriends"];
}];
请建议我在哪里做错了。提前谢谢。
答案 0 :(得分:1)
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,NSDictionary* result,NSError *error)
{
NSArray* friends = [result objectForKey:@"data"];
//NSLog(@"%@",friends);
[app.Arr_Facebook_Frnd removeAllObjects];
// CREATE ARRAY OF ALL FRIEND LIST OF FACEBOOK
for (int i=0; i < [friends count]; i++)
{
// ADD IMAGE URL IN ARRAY
NSString *s1=[NSString stringWithFormat:@"%@",[[friends objectAtIndex:i] objectForKey:@"first_name"]];
NSString *s2=[NSString stringWithFormat:@"%@",[[friends objectAtIndex:i] objectForKey:@"id"]];
NSString *s3=[NSString stringWithFormat:@"%@",[[friends objectAtIndex:i] objectForKey:@"last_name"]];
NSString *s4=[NSString stringWithFormat:@"%@",[[friends objectAtIndex:i] objectForKey:@"name"]];
NSString *s5=[NSString stringWithFormat:@"%@",[[friends objectAtIndex:i] objectForKey:@"username"]];
NSString *s6=[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?", [[friends objectAtIndex:i] objectForKey:@"id"]];
NSMutableDictionary *dictFriend=[[NSMutableDictionary alloc]init];
[dictFriend setObject:s1 forKey:@"first_name"];
[dictFriend setObject:s2 forKey:@"id"];
[dictFriend setObject:s3 forKey:@"last_name"];
[dictFriend setObject:s4 forKey:@"name"];
[dictFriend setObject:s5 forKey:@"username"];
[dictFriend setObject:s6 forKey:@"ImgUrl"];
[app.Arr_Facebook_Frnd addObject:dictFriend];
[dictFriend release];
}
[app.Arr_Facebook_Frnd retain];
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
[app.Arr_Facebook_Frnd sortUsingDescriptors:sortDescriptors];
[sortDescriptor release];
[self.indicator stopAnimating];
}];
答案 1 :(得分:1)
如果您的应用不是游戏,这可能是正常行为。
看看这个答案:
Facebook Graph Api v2.0+ - /me/friends returns empty, or only friends who also use my app