【问题标题】:Unable to get Facebook user info (birthday, work, education)无法获取 Facebook 用户信息(生日、工作、教育)
【发布时间】:2017-01-27 02:32:52
【问题描述】:

我很难通过 Facebook SDK 获取用户信息。

我正在努力争取生日、工作和教育。

我正在使用这个:

 let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"education, work, email, id, name, first_name, last_name, birthday, gender"])

该电话不提供教育、工作或生日。

我拥有 Facebook 批准的以下权限:

  • user_birthday
  • user_education_history
  • user_work_history

当我尝试在上面的代码示例中使用这些值时,应用程序会因不存在的字段而崩溃:

type (User), com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode=100, com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={
    body =     {
        error =         {
            code = 100;
            "fbtrace_id" = CVy14JLKraa;
            message = "(#100) Tried accessing nonexisting field (user_birthday) on node type (User)";
            type = OAuthException;
        };
    };
    code = 400;
}}

当我尝试使用带有用户 ID 的图形请求而不是我时:

let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "/\(fbid)", parameters: ["fields":"user_birthday"])
                    graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in ...

我也遇到同样的错误:

 message = "(#100) Tried accessing nonexisting field (user_birthday) on node type (User)";

有什么建议吗?

【问题讨论】:

标签: ios swift facebook facebook-graph-api


【解决方案1】:

请遵照执行。 可能对你有用。

#define K_Field @"fields"
#define K_Permission @"email,location, birthday, name, link"
#define K_ID @"id"
#define K_Name @"name"
#define K_DOB @"birthday"
#define K_Email @"email"



        FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
        [login logOut];
        login.loginBehavior = FBSDKLoginBehaviorWeb;

        [login
         logInWithReadPermissions: @[K_Email]
         fromViewController:self
         handler:^(FBSDKLoginManagerLoginResult *user, NSError *error) {
             if (error || user.isCancelled) {
                 NSLog(@"Process error");
             } else {
                 if ([FBSDKAccessToken currentAccessToken]) {
                     [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{K_Field: K_Permission}]
                      startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
                          if (!error) {
                              NSLog(@"fetched user:%@", result);
                              //Done login
                          }
                      }];
                 }
             }
         }];

请确保您使用正确的关键字与facebook official docs相同

【讨论】:

    【解决方案2】:

    可以通过收集用户的 id 并从 Graph API 访问中获取公共详细信息来使用 Facebook Graph API:

    $fb->get('/me?fields=name,first_name,last_name,email,birthday');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-02
      • 1970-01-01
      • 2019-04-29
      • 1970-01-01
      • 2011-04-10
      相关资源
      最近更新 更多