iOS Facebook SDK: An active access token must be used to query information about the current user

一笑奈何 提交于 2019-11-30 07:03:11

According to the docs, https://developers.facebook.com/docs/reference/ios/3.1/class/FBRequestConnection

"The request uses the active session represented by [FBSession activeSession]."

This applies to the static methods dealing with requests. So what you want to do is make sure you set the active session. Do the following:

[FBSession setActiveSession:self.fb];

Just before you call the first FBRequestConnection start* method.

Well After some time, noticing that FBSession.activeSession was not nil, what I was missing before sending the request was:

    if (!FBSession.activeSession.isOpen) {
        [FBSession openActiveSessionWithAllowLoginUI: YES];
    }

I got this error in v4 of the SDK when attempting to use a FBSDKGraphRequest object that had been created before logging in. When I changed this to create the FBSDKGraphRequest immediately before using it (i.e. after having logged in) it worked fine. It seems the initializer for this class sets some token that isn't refreshed when the request is started.

I tried updating the request's tokenString property after logging in, but for some reason this is a readonly property.

/* deprecated for google and facebook func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: AnyObject) -> Bool { let googleDidHandle = GIDSignIn.sharedInstance().handle(url, sourceApplication: sourceApplication, annotation: annotation)

    let facebookDidHandle = FBSDKApplicationDelegate.sharedInstance().application(
        application,

open: url, sourceApplication: sourceApplication, annotation: annotation) print(facebookDidHandle) return googleDidHandle || facebookDidHandle } */

So i used, func application(_ application: UIApplication, open url: URL, options: [String: AnyObject]) -> Bool {

    return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: options) || GIDSignIn.sharedInstance().handle(url as URL!, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as! String, annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
}

xcode 8 beta 3 , ios 10

kavita patel

you can try this too, works for me

func application(_ application: UIApplication,
                      open url: URL, 
                       options: [String: AnyObject]) -> Bool
{
    let delegate = FBSDKApplicationDelegate.sharedInstance()

    return delegate.application(application, open: url, 
                                sourceApplication: options["UIApplicationOpenURLOptionsSourceApplicationKey"] as! String, 
                                       annotation: options["UIApplicationOpenURLOptionsAnnotationKey"])
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!