Facebook ios sdk图形请求仅允许一个字段作为参数

Facebook ios sdk图形请求仅允许一个字段作为参数,ios,swift,facebook,facebook-graph-api,fbsdk,Ios,Swift,Facebook,Facebook Graph Api,Fbsdk,我正在开发一个需要facebook登录和用户详细信息的应用程序。但是,我在以前的fb登录应用程序中使用的代码不起作用,我需要为每个字段(如姓名、电子邮件、图片等)分别请求图形 基本上,每当我尝试执行以下操作时: connection.add(GraphRequest(graphPath: "/me", parameters:["fields":"email, name, picture"])) { httpResponse, result in switch re

我正在开发一个需要facebook登录和用户详细信息的应用程序。但是,我在以前的fb登录应用程序中使用的代码不起作用,我需要为每个字段(如姓名、电子邮件、图片等)分别请求图形

基本上,每当我尝试执行以下操作时:

connection.add(GraphRequest(graphPath: "/me", parameters:["fields":"email, name, picture"])) { httpResponse, result in
                switch result {
                case .success(let response):
                    guard let userInfo = response.dictionaryValue else {
                        return
                    }
                    userDict["email"] = userInfo["email"]! as Any
                    UserDefaults.standard.set(userDict["email"], forKey: userKeys.email)
                case .failed(let error):
                    print("Graph Request Failed: \(error)")
                }
            }
我得到这个错误:

Graph Request Failed: Error Domain=com.facebook.sdk.core Code=8 "(null)" UserInfo={com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey=0, com.facebook.sdk:FBSDKGraphRequestErrorHTTPStatusCodeKey=400, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Syntax error "Expected end of string instead of "%"." at character 5: email%2C%20name%2C%20picture, com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode=2500, com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={
body =     {
    error =         {
        code = 2500;
        "fbtrace_id" = "FIc1yiUL+1z";
        message = "Syntax error \"Expected end of string instead of \"%\".\" at character 5: email%2C%20name%2C%20picture";
        type = OAuthException;
    };
};
code = 400;
当我这样做时,也会出现类似的错误:

connection.add(GraphRequest(graphPath: "/me", parameters:["fields":"picture.type(large)"]))
但是,当我将单个字段作为参数输入时,它不会给出错误

任何帮助都将不胜感激:)

试试这个

    let loginManager = FBSDKLoginManager()
    loginManager.logOut()
    loginManager.logIn(withReadPermissions: ["public_profile", "user_photos" ,"user_videos"], from: self) { (result, error) in
        if error != nil {

        } else if (result?.isCancelled)! {
            print("Cancelled")
        } else {               
            let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields" : "email, id, name"])
            graphRequest.start(completionHandler: { (connection, result, error) -> Void in
                if ((error) != nil) {
                    print("Error: \(String(describing: error))")
                } else {
                    var userName:String?
                    var userID:String?
                    var userIEmail:String? = ""
                    if let user : NSString = (result! as AnyObject).value(forKey: "name") as? NSString {
                        userName = "\(user)"
                    }
                    if let id : NSString = (result! as AnyObject).value(forKey: "id") as? NSString {
                        userID = id as String
                        if userID == UserDefaultsHelper.username{
                            self.ClearUserData = false
                        }
                    }
                    if let email : NSString = (result! as AnyObject).value(forKey: "email") as? NSString {
                        userIEmail = email as String
                    }
                }
            })
        }
    }

我在尝试最新版本时也遇到了同样的错误。我建议你降级到以前的版本。对我来说,以下版本运行良好:

pod 'FBSDKCoreKit', '~> 4.38.0' 
pod 'FBSDKLoginKit', '~> 4.38.0' 
在那次跑步之后

pod去集成


pod安装

否,给出了相同的错误:“字符5处的字符串结尾应为“%”,而不是“%”:电子邮件%2C%20id%2C%20name“我也很想知道这个问题的答案,自从昨晚我更新了播客后,我就遇到了同样的问题。我在FB登录时遇到了其他问题,发现另一篇文章解释了SDK 4.39.0存在问题,可能这与相同的问题有关。。。我的代码正在工作,不再与pod更新一起工作