只有在我升级到xCode 9之后才开始出现此错误。在此之前,我从未遇到过这个问题,并且没有任何更改。当我发出图形请求时,我收到以下错误:
- some: 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" = HV5mzgqALtD;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
};
code = 400;
}} #0
我不确定为什么我会收到有关访问代码的错误,我确实包含它,之前不是问题,它已经传递给Firebase了。我已经更新了所有的pod,尝试清理构建,仔细检查了我的Facebook开发帐户,在xCode中仔细检查了FBSDK的配置,我能想到的一切。
这是我的图表请求:
func fetchFacebookInfoForFirstTimeUser(_ firebaseUser:User) {
print("fetchFacebookInfoForFirstTimeUser")
let params = ["fields": "education, name, first_name, last_name, birthday, email, gender, locale, timezone, work, picture.type(large)"]
let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: params)
_ = graphRequest?.start { [weak self] connection, result, error in
guard let weakSelf = self else { return }
// If something went wrong, we're logged out
if (error != nil) {
dump(error)
return
}
// Whole bunch of stuff processing the data
}
}
以下是用于登录Facebook和Firebase的所有代码:
/* ------------------ FACEBOOK -------------------- */
/* ----------------------------------------------- */
@objc func handleCustomFBLogin() {
let permissions = ["public_profile", "email", "user_birthday", "user_location", "user_education_history", "user_work_history", "user_friends"]
FBSDKLoginManager().logIn(withReadPermissions: permissions, from: self) {
(result, err) in
if err != nil {
print("FB Login Failed:", err!)
return
} else {
print("FB Login Success!")
self.connectToFirebase()
Util.showLoadingIcon(uiView: self.view)
}
}
}
/* ------------------ FIREBASE ------------------ */
/* --------------------------------------------- */
func connectToFirebase() {
print("connecting to Firebase")
let accessToken = FBSDKAccessToken.current()
guard let accessTokenString = accessToken?.tokenString else { return }
let credentials = FacebookAuthProvider.credential(withAccessToken: accessTokenString)
Auth.auth().signIn(with: credentials, completion: { (user, error) in
// Auth.auth().signIn(withEmail: "test@gmail.com", password: "111111", completion: { (user, error) in
if error != nil {
print("Something went wrong with our FB user:", error ?? "" )
return
}
// Update FCM TOKEN
var token = "A1"
if let t = InstanceID.instanceID().token(){
token = t
}
print("fcmToken: \(token)")
let l = Database.database().reference(withPath: "users/\(user!.uid)")
l.updateChildValues(["fcmToken": token])
// Successfully logged in, let's move on
print("Successfully logged into Firebase!")
self.configureAppForUser(curUser: user!)
print(user!.uid)
})
}
func configureAppForUser(curUser: User) {
// Grab the current user's data
// self.pushDashboardViewController()
print("configureAppForUser")
ref.child("users").child(curUser.uid).observeSingleEvent(of: .value, with: { (snapshot) in
if snapshot.value is NSNull {
print("First time user")
// User does not have any data in Firebase, so get FB data and show onboarding
self.fetchFacebookInfoForFirstTimeUser(curUser)
} else {
print("Existing user")
let json = JSON(snapshot.value!)
if json["onboarded"] == JSON.null || json["onboarded"] == false {
print("User has NOT onboarded")
// User has not onboarded, show onboarding screen
self.fetchFacebookInfoForFirstTimeUser(curUser)
} else {
print("User HAS onboarded")
// User HAS onboarded, go to home screen
UserDefaults.standard.set(true, forKey: "KnownUser\(String(describing: curUser.uid))")
self.pushDashboardViewController()
}
}
}) { (error) in
print(error.localizedDescription)
}
}