ios - FBSDKLog : starting with Graph API v2. 4、对/me/permissions的GET请求应包含显式的 "fields"参数

标签 ios xcode facebook swift

有谁知道为什么我会收到此错误?我有一个字段参数集。我对 swift 和编码很陌生,任何帮助将不胜感激。

let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, gender"])

    // start the request:
    graphRequest.startWithCompletionHandler({

        // void in means that it will return nothing upon completion
        (connection, result, error) -> Void in

        // do an error check
        if error != nil {


            print(error)


        } else if let result = result {

            PFUser.currentUser()?["gender"] = result["gender"]
            PFUser.currentUser()?["name"] = result["name"]
            PFUser.currentUser()?.save()


            // use the user's FB id to get their public profile. First make their id a string:
            let userId = result["id"] as! String
            // next go to the internet and get their photo from FB:
            let facebookProfilePictureUrl = "https://graph.facebook.com/" + userId + "/picture?type=large"

最佳答案

有一种方法可以让您获得对象“me”,然后您可以获取该对象的每个值

let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil)
    graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in
        if (error) != nil   {
            NSLog("Error: \(error)")
            ActivityIndicatorWithLabel.shared.hideProgressView()
            view.makeToast(message: "We are unable to connect to Facebook. Please try after sometime")
        }else{
            self.facebookData(result)
        }
    })

在此结果中,我们获得了用户的所有详细信息 这是一种从中获取的方法

func facebookData(result: AnyObject){
    NSLog("Sending Login from facebook call")
    var missingFields:[String] = []
    userSocialDetailsGlobal.loginType = "facebook"
    userSocialDetailsGlobal.socialId = result.valueForKey("id") as! String
    userSocialDetailsGlobal.firstName = result.valueForKey("first_name") as! String
    userSocialDetailsGlobal.lastName = result.valueForKey("last_name") as! String

    userSocialDetailsGlobal.socialToken = FBSDKAccessToken.currentAccessToken().tokenString
}

struct userSocialDetailsGlobal {
    static var socialId: String = String()
    static var firstName: String = String()
    static var lastName: String = String()
    static var loginType: String = String()
    static var socialToken: String = String()
}

关于ios - FBSDKLog : starting with Graph API v2. 4、对/me/permissions的GET请求应包含显式的 "fields"参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32539670/

相关文章:

facebook - 分享按钮/张贴到墙上 - Facebook API?

iOS 核心动画 : Show and hide effect

ios - 将应用程序上传到 iTunes 连接时如何解决 Xcode 验证错误?

ios - UIVisualEffectView 延迟与 UIModalTransitionStyle CrossDissolve

Facebook 应用程序 : Additional permissions

ios - 解析 Facebook 登录应用程序必须请求基本读取权限

ios - Xcode 隐藏按钮

xcode - 线程 1 : Stopped at breakpoint 1

objective-c - 我如何检查 ALAsset 是一个图像。我如何从 ALAssetGroup 中分离图像(.png)文件

xcode - @Published ObservedObjects SwiftUI 更新未发生