2012-12-13 86 views
2

任何人都可以幫助我。我無法弄清楚如何使用最新的Facebook SDK(v 3.1)爲iOS創建單個FQL查詢來獲取用戶朋友的生日和電子郵件。當我查詢名稱這樣的字段時,我會得到正確的值,但在電子郵件和生日字段中爲空。使用v3.1的FQL查詢Facebook SDK for iOS獲取生日和電子郵件

這裏是我的代碼

- (void)facebookViewControllerDoneWasPressed:(id)sender { 

    // we pick up the users from the selection, and create a string that we use to update the text view 
    // at the bottom of the display; note that self.selection is a property inherited from our base class 
    for (id<FBGraphUser> user in _friendPickerController.selection) { 
     _nameTxt.text = user.name; 
     NSString *fql = [NSString stringWithFormat:@"SELECT email, birthday, name FROM user WHERE uid = %@ ",user.id]; 
     NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObject:fql forKey:@"q"]; 
     [FBRequestConnection startWithGraphPath:@"/fql" 
            parameters:params 
            HTTPMethod:@"GET" 
           completionHandler:^(FBRequestConnection *connection, 
               id result, 
                 NSError *error) { 
            if (error) { 
             NSLog(@"Error: %@", [error localizedDescription]); 
            } else { 
             NSLog(@"Result: %@", result); 
            } 
           }]; 

    } 
    [self.navigationController dismissModalViewControllerAnimated:YES]; 
} 

我收到的電子郵件和生日的名稱值,但空。

感謝

+0

權限有什麼你應用程序要求?你有沒有要求電子郵件和user_birthday? –

+0

@CAbernathy我不這麼認爲,我的應用程序正在要求這些權限。我是這個Facebook Graph API的新手,你能告訴我我需要做什麼嗎? –

+0

這個問題讓我得到了我無法在其他地方找到答案。 –

回答

3

之前,你打電話給你的查詢,你需要有用戶登錄,並要求郵件和user_birthday權限。例如:

https://developers.facebook.com/docs/howtos/login-with-facebook-using-ios-sdk/

還檢查了FQL教程:

- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI { 
    NSArray *permissions = [[NSArray alloc] initWithObjects: 
         @"email", 
         @"user_birthday", 
         nil]; 
    return [FBSession openActiveSessionWithReadPermissions:permissions 
              allowLoginUI:allowLoginUI 
            completionHandler:^(FBSession *session, 
                FBSessionState state, 
                NSError *error) { 
            [self sessionStateChanged:session 
                 state:state 
                 error:error]; 
           }]; 
} 

地,上述方法在本教程的上下文中使用

https://developers.facebook.com/docs/howtos/run-fql-queries-ios-sdk/

相關問題