2016-09-20 51 views
2

我想用swift 3.0將Facebook登錄集成到iOS 10應用程序中。 我得到錯誤代碼2500爲設置在FacebookSDK到應用程序後如下所示:錯誤代碼2500在Swift 3.0上的Facebook登錄

錯誤代碼在控制檯上:

body =  { 
    error =   { 
     code = 2500; 
     "fbtrace_id" = FpAkfsaBAFc; 
     message = "An active access token must be used to query information about the current user."; 
     type = OAuthException; 
    }; 
}; 
code = 400; 
}}) 

loginButton功能上loginViewController:

func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) { 

    fetchProfile() 
    print("@@@@Completed [email protected]@@@") 

} 

在loginVC上獲取Facebook個人資料功能:

func fetchProfile() { 


    let parameters = ["fields": "email, first_name, last_name, picture.type(large)"] 

    FBSDKGraphRequest(graphPath: "me", parameters: parameters).start(completionHandler: { (connection, user, requestError) -> Void in 

     if requestError != nil { 
      print(requestError) 
      print("There are some error during getting the request from fb") 
      return 
     } 

     self.email = (user?["email"] as? String)! 
     self.firstName = (user?["first_name"] as? String)! 
     self.lastName = (user?["last_name"] as? String)! 

     self.nameLabel.text = "\(self.firstName) \(self.lastName)" 
     print("My fbname is " + self.firstName) 
     print(self.lastName) 

     var pictureUrl = "" 

     if let picture = user?["picture"] as? NSDictionary, let data = picture["data"] as? NSDictionary, let url = data["url"] as? String { 
      pictureUrl = url 
      print(pictureUrl) 
     } 

    }) 
} 

AppDelegate.swift

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
    // Override point for customization after application launch. 

    FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) 

    return true 
} 



func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: AnyObject) -> Bool { 
    return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation) 
} 

本來上搜索堆棧溢出類似的問題,但不工作的SWIFT 3.0,將不勝感激,如果任何人都可以在這個問題上,謝謝指教,有一個很好的天!

回答

1

我已經解決了這個問題的鑰匙串接入已經在默認情況下iOS10被禁用,啓用鑰匙鏈共享能力和Facebook登錄工作完美!

1

如錯誤消息所示,您缺少access_token。在提出請求之前先進行控制,並檢查access_token是否爲零,然後請求一個新的請求。之後,你應該可以提出你的要求。

+1

注意謝謝! – aznelite89