2012-08-28 87 views
2

我想讓我的好友家鄉&使用FB SDK for iOS的位置。但我無法檢索朋友位置&家鄉。這是我的代碼使用Facebook SDK 3.0 for iOS檢索Facebook好友的家鄉&位置和生日

- (IBAction)btnFBLoginTapped:(id)sender { 

    NSArray *permissions = [[NSArray alloc]initWithObjects:@"email",@"user_birthday",@"user_hometown",@"user_location",@"friends_birthday",@"friends_location",@"friends_hometown", nil]; 

    [FBSession openActiveSessionWithPermissions:permissions allowLoginUI:YES 
           completionHandler:^(FBSession *session, 
                FBSessionState status, 
                NSError *error) { 
            // session might now be open. 
            if (session.isOpen) { 
             FBRequest *me = [FBRequest requestForMe]; 
             [me startWithCompletionHandler: ^(FBRequestConnection *connection, 
                     NSDictionary<FBGraphUser> *my, 
                     NSError *error) { 
              NSLog(@"My dcitionary:- %@",my); 
              NSLog(@"Sessionkey:- %@",session.accessToken); 
              // Friend request 

              FBRequest *friendRequest = [FBRequest requestForMyFriends]; 

              [friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) { 
               NSDictionary *resultDictionary = (NSDictionary *)result; 

               NSArray *data = [resultDictionary objectForKey:@"data"]; 

               NSLog(@"Data:- %@",data); 

               for (NSDictionary *dic in data) { 
                NSLog(@"ID:- %@",[dic objectForKey:@"id"]); 
               } 
              }]; 
             }]; 
            } 
           }]; 
} 

此外我需要檢索朋友的生日。但我也不能檢索生日。

有人可以幫忙嗎?

回答

0

在這一點上

.... 
[friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) { 
    NSDictionary *resultDictionary = (NSDictionary *)result; 

你的結果應該是一個NSArray,不是一個NSDictionary檢查你的邏輯。

還有一兩件事要仔細檢查的結果是把類似的查詢在圖形API資源管理器:https://developers.facebook.com/tools/explorer

你會把我/朋友在圖形API探險 提示:選擇您以前在同一個應用程序在Graph API瀏覽器的應用程序下拉列表中設置。

3

dataFBGraphObject<FBGraphUser>

[friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) { 
    NSArray *data = [result objectForKey:@"data"]; 

    for (FBGraphObject<FBGraphUser> * user in data) { 
     NSLog(@"%@", [user first_name]); 
    } 
... 
陣列
相關問題