2013-03-23 127 views
1

我只需要爲iOS用戶使用Facebook圖形API圖形API獲取朋友總數。如何檢索使用Facebook圖形API的朋友總數

我看到了一個示例,顯示如何檢索用戶列表(e.x名稱)。但是,就我而言,我不需要獲取好友列表,我只需要獲取好友總數。因此,我認爲將整個清單計算在總數中將是低效率的。

任何提示如何我可以得到使用Acebook圖API API圖形API的朋友的總數。

回答

2

我找到了答案,只需使用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); 
           } 
          }]; 
} 
1

,瞭解這一點很重要,那結果可能會有所不同。

儘管user_count的FQL查詢會爲您提供朋友的實際數量(在您的個人資料上可見),但計數圖譜API中的朋友只會顯示沒有完全禁用應用平臺的朋友(在隱私設置/應用中),例如爲我的朋友列表:303「真正的朋友」,只有294,如果我數圖api結果!

相關問題