Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Offline' access with HybridAuth

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!

like image 514
Marc Avatar asked Oct 30 '12 21:10

Marc


2 Answers

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";
    }
like image 93
Marc Avatar answered Oct 09 '22 22:10

Marc


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

like image 38
rinogo Avatar answered Oct 09 '22 20:10

rinogo