Question

I have already authorized a user in my Facebook application using HybridAuth and stored his access_token in my database.

Days later, when the user is not online, I want to get his new Facebook friends, also using HybridAuth.

Can I 'recreate' that user from his access_token to get his friends, send notifications, etc.?

Thanks!

Was it helpful?

Solution

I finally found a hack that works, I'll leave it here for the next guy looking for it. If you make sure that you have a valid token for your user and app, HybridAuth should not try to redirect or return any errors

(I'm using Codeigniter, but translating it to 'pure' HybridAuth should be straightforward:

    $token = "GET A TOKEN IN Facebook's API EXPLORER";
    $this->load->library('HybridAuthLib');
    $this->hybridauthlib->storage()->set( "hauth_session.facebook.is_logged_in", 1 );
    $this->hybridauthlib->storage()->set( "hauth_session.facebook.token.access_token", $token );        
    $service = $this->hybridauthlib->authenticate('Facebook');

    if ($service->isUserConnected()){

        $user_profile = $service->getUserProfile();
        $contacts = $service->getUserContacts();
        $access_token = $service->getAccessToken();

        var_dump($user_profile);
        var_dump($contacts);
        var_dump($access_token);

    }else{
        echo "something went wrong";
    }

OTHER TIPS

While the above may work, I believe the recommend approach may be to use "Persistent Sessions" as described here: http://hybridauth.sourceforge.net/userguide/HybridAuth_Sessions.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top