iam*_*rak 1 xcode facebook facebook-graph-api ios facebook-login
我刚刚更新了手机iOS11.3和Xcode 9.3,facebook登录就像我的旧SDK调用一样崩溃:
https://pasteboard.co/HeeRDVo.png
我不明白这究竟是什么意思,即使它适用于旧版本.然后我从该页面应用了Swift SDK, https://developers.facebook.com/docs/swift/graph.
import FacebookCore
let connection = GraphRequestConnection()
connection.add(GraphRequest(graphPath: "/me")) { httpResponse, result in
switch result {
case .success(let response):
print("Graph Request Succeeded: \(response)")
case .failed(let error):
print("Graph Request Failed: \(error)")
}
}
connection.start()
Run Code Online (Sandbox Code Playgroud)
这给出了以下错误日志:
FBSDKLog: starting with Graph API v2.4, GET requests for //me should contain an explicit "fields" parameter
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=An active access token must be used to query information about the current user., com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode=2500, com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={
body = {
error = {
code = 2500;
"fbtrace_id" = ____id____;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
};
code = 400;
}}
Run Code Online (Sandbox Code Playgroud)
它说,必须使用活动访问令牌来查询有关当前用户的信息.
当我制作字典注释行时,即使在代码块下面也会出现相同的错误,因为它们也不起作用.
import FacebookCore
struct MyProfileRequest: GraphRequestProtocol {
struct Response: GraphResponseProtocol {
init(rawResponse: Any?) {
// Decode JSON from rawResponse into other properties here.
}
}
var graphPath = "/me"
var parameters: [String : Any]? = ["fields": "id, name"]
var accessToken = AccessToken.current
var httpMethod: GraphRequestHTTPMethod = .GET
var apiVersion: GraphAPIVersion = .defaultVersion
}
let connection = GraphRequestConnection()
connection.add(MyProfileRequest()) { response, result in
switch result {
case .success(let response):
print("Custom Graph Request Succeeded: \(response)")
print("My facebook id is \(response.dictionaryValue?["id"])")
print("My name is \(response.dictionaryValue?["name"])")
case .failed(let error):
print("Custom Graph Request Failed: \(error)")
}
}
connection.start()
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能克服这个问题?
iam*_*rak 11
最后,我使用下面的方法而不是AppDelegate中的注释open url方法解决了我的问题.希望它能帮助在iOS 11.3中遇到此问题的其他人.
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(app,
open: url,
sourceApplication: options[.sourceApplication] as! String,
annotation: options[.annotation])
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1330 次 |
| 最近记录: |