Xcode 9.3 的 Facebook SDK 访问令牌问题
Facebook SDK access token issue with Xcode 9.3
我刚刚更新了 phone 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()
给出以下错误日志:
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;
}}
它说,必须使用活动访问令牌来查询有关当前用户的信息。
当我创建词典注释行时,甚至下面的代码块也会出现同样的错误,因为它们也不起作用。
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()
我应该怎么做才能克服这个问题?
最后,我使用以下方法解决了我的问题,而不是在 AppDelegate 中使用注解打开 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])
}
我刚刚更新了 phone 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()
给出以下错误日志:
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;
}}
它说,必须使用活动访问令牌来查询有关当前用户的信息。
当我创建词典注释行时,甚至下面的代码块也会出现同样的错误,因为它们也不起作用。
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()
我应该怎么做才能克服这个问题?
最后,我使用以下方法解决了我的问题,而不是在 AppDelegate 中使用注解打开 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])
}