ios - Facebook ios sdk Graph 请求只允许一个字段作为参数
问题描述
我正在开发一个需要 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)"]))
但是,当我将单个字段作为参数输入时,它不会出错。
任何帮助将不胜感激 :)
解决方案
尝试使用最新版本时,我也遇到了同样的错误。我建议你降级到以前的版本。对我来说,以下版本工作正常:
pod 'FBSDKCoreKit', '~> 4.38.0'
pod 'FBSDKLoginKit', '~> 4.38.0'
在那次运行之后
pod deintegrate
pod install
推荐阅读
- java - 在 JavaFX 中将 TableView 与实体类一起使用
- c# - 如何实现检查对象状态变化的 NUnit 测试?
- c# - 范围报告:无法在其他机器上看到屏幕截图(C#-NUnit)
- amazon-web-services - 物联网 - 来自设备的实时视频流
- javascript - 从不同的方式读取数组给了我不同的结果
- amazon-web-services - AWS Cognito 角色:区分联合身份池角色和用户池组角色
- javascript - 如何解决 graphql 突变上的嵌套输入类型
- cmd - 如何处理用户名中的空格作为命令中的参数
- python - 有没有更有效的方法将 Pandas DataFrames 存储到 CSV?
- struct - 有没有办法让结构类型数组写入文件?