如何检索使用Facebook图形API的朋友总数

问题描述:

我只需要为iOS用户使用Facebook图形API图形API获取朋友总数。如何检索使用Facebook图形API的朋友总数

我看到了一个示例,显示如何检索用户列表(e.x名称)。但是,就我而言,我不需要获取好友列表,我只需要获取好友总数。因此,我认为将整个清单计算在总数中将是低效率的。

任何提示如何我可以得到使用Acebook图API API图形API的朋友的总数。

我找到了答案,只需使用FBL查询:SELECT friend_count FROM user WHERE uid = me()

等完整的代码将是:

- (void)queryButtonAction { 

    NSString *query [email protected]"SELECT friend_count FROM user WHERE uid = me()"; 

    // Set up the query parameter 
    NSDictionary *queryParam = 
    [NSDictionary dictionaryWithObjectsAndKeys:query, @"q", nil]; 
    // Make the API request that uses FQL 
    [FBRequestConnection startWithGraphPath:@"/fql" 
           parameters:queryParam 
           HTTPMethod:@"GET" 
          completionHandler:^(FBRequestConnection *connection, 
               id result, 
               NSError *error) { 
           if (error) { 
            NSLog(@"Error: %@", [error localizedDescription]); 
           } else { 
            NSLog(@"Result: %@", result); 
            // show result 
            NSArray *friendInfo = (NSArray *) [result objectForKey:@"data"]; 
            NSLog(@"result=%@",[friendInfo objectAtIndex:0]); 
            NSDictionary *friend_count =[friendInfo objectAtIndex:0]; 
            NSString *numberoff= [friend_count objectForKey:@"friend_count"]; 
            NSLog(@"Result2: %@", numberoff); 
           } 
          }]; 
} 

,了解这一点很重要,那结果可能会有所不同。

尽管user_count的FQL查询会为您提供朋友的实际数量(在您的个人资料上可见),但计数图谱API中的朋友只会显示没有完全禁用应用平台的朋友(在隐私设置/应用中),例如为我的朋友列表:303“真正的朋友”,只有294,如果我数图api结果!