我在我的应用程序中集成了Facebook。但登录FBSDKAccessToken后。currentAccessToken()发现为零。
下面是我的代码:
override func viewDidLoad() {
if (FBSDKAccessToken.currentAccessToken() != nil)
{
print("Not loggedin...")
}
else
{
print("logged in...")
}
loginbutton.delegate = self
loginbutton.readPermissions = ["public_profile", "email", "user_friends"]
}
func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
if(error == nil)
{
print("login complete")
print(result)
print(result.grantedPermissions)
}
else{
print(error.localizedDescription)
}
if let userToken = result.token
{
let token:FBSDKAccessToken = result.token
print("TOKEN = \(FBSDKAccessToken.currentAccessToken().tokenString)")
print("User ID = \(FBSDKAccessToken.currentAccessToken().userID)")
}
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"name, email"])
graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in
if ((error) != nil)
{
// Process error
print("Error: \(error)")
}
else
{
print("fetched user: \(result)")
let userEmail : NSString = result.valueForKey("email") as! NSString
print("User Email is: \(userEmail)")
let userName : NSString = result.valueForKey("name") as! NSString
print("User Name is: \(userName)")
}
})
}
func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
print("User Logged Out")
}
登录后,我得到一个空白屏幕。它打印登录成功的消息,但它不是进入这个:
if let userToken = result.token
{
let token:FBSDKAccessToken = result.token
print("TOKEN = \(FBSDKAccessToken.currentAccessToken().tokenString)")
print("User ID = \(FBSDKAccessToken.currentAccessToken().userID)")
}
所以,我没有得到任何令牌。而它去打印电子邮件它显示这个错误:
这是我在appdelegate中代码
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool
{
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
func applicationDidBecomeActive(application: UIApplication) {
FBSDKAppEvents.activateApp()
}
func application(application: UIApplication,
openURL url: NSURL, options options: [String: AnyObject]) -> Bool {
return GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey]! as! String,
annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
}
实际上每次它调用的openurl方法的gmail集成,所以我怎么能把条件调用的方法的facebook集成
1条答案
按热度按时间t30tvxxf1#
在您代码中做以下更改,它将工作
调用此方法以获取用户电子邮件ID
请删除此方法
更改此方法实现