【问题标题】:Can not fetch email from Facebook in Swift无法在 Swift 中从 Facebook 获取电子邮件
【发布时间】:2015-11-04 19:01:45
【问题描述】:

编辑:这个问题的问题有点傻。和answer 一样,问题是我没有给出我想要的参数。

我再也受不了了 :) 可能是什么问题?

    func returnUserData()
{
    let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil)
    graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in

        if ((error) != nil)
        {
            // Process error
            print("Error: \(error)")
        }
        else
        {
            print("fetched user: \(result)")
            let userName : NSString = result.valueForKey("name") as! NSString
            print("User Name is: \(userName)")
            let userEmail : NSString = result.valueForKey("email") as! NSString
            print("User Email is: \(userEmail)")
        }
    })
}

我这样调用函数:

    func loginButton(loginButton: FBSDKLoginButton!,
    didCompleteWithResult result: FBSDKLoginManagerLoginResult!,
    error: NSError!) {
        print("User Logged In")

        if ((error) != nil)
        {
            // Process error
        } else if result.isCancelled {
            // Handle cancellations
        } else {
            // If you ask for multiple permissions at once, you
            // should check if specific permissions missing
            if result.grantedPermissions.contains("email")
            {
                // Do work
                returnUserData()
            }
        }
}

我得到错误:

我的问题是关于致命错误。但是,我正在等待输出的第 2 行和第 3 行的 cmets。因为,我每次都得到这个输出,但应用程序运行正常。

【问题讨论】:

  • 您的 fields 参数为零,正如您的错误消息所说“从 Graph API v 2.4 开始,我的 GET 请求应该包含一个明确的 fields 参数”

标签: swift facebook-login facebook-sdk-4.0


【解决方案1】:

您必须为请求指定参数。

let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "first_name, last_name, email"])

【讨论】:

    猜你喜欢
    • 2018-03-06
    • 2015-11-07
    • 2020-06-18
    • 1970-01-01
    • 2018-08-10
    • 2021-04-29
    • 2015-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多