facebookhybridauthhybridauthprovider

'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!


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";
        }