提问者:小点点

脸书阅读朋友列表没有给我完整的iOS SDK中的朋友列表[重复]


我正在使用社交框架检索脸书朋友列表。请看看我的以下代码,我是怎么做的,但它只给了我几个朋友,而不是全部。我检查了两个帐户,1个帐户有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"];

         }];

请建议我做错什么。提前致谢。


共2个答案

匿名用户

如果你的应用不是游戏,这可能是正常的行为。

看看这个答案:

脸书图表 Api v2.0 - /me/好友返回空的,或仅返回也使用我的应用程序的好友

匿名用户

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];
 }];