Using Google's API through laravel/hybridauth

743 views Asked by At

I want to create an app that uses Google+ APIs through hybridauth.

I'm using atticmedia/anvard version of hybridauth, that is already configured with Google's clientID and secretKey that have been generated through Google Developer Console (I have inserted these info inside the hybridauth.php file inside the config folder of laravel). I have setted the scope too (as Google suggest).

"scope"   => "https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email",

I do the following in a laravel route:

if (!$hybridauth->isConnectedWith('Google')) {
    $adapter = $hybridauth->authenticate('Google');
}
else {
    $adapter = $hybridauth->getAdapter('Google');
}

$profile = $adapter->getUserProfile();

Till now, everything goes well. The profile is correctely printed using the var_dump() function. So I can assume I am logged in. Now I want to make a call to Google APIs (for example this). In the same laravel route, after printing the user's profile, i do the following:

$answer= $adapter->api()->api('/people', 'get', array(
                                        'query' => 'Google'
                                    ));

As shown in this page, I can use the api() method to do the call. But the only result I can print is "NULL". I suspect that somehow the request is not correct, but I tryed almost anything, and I have not found yet a "real" example of Google API in conjuction with laravel/hybridauth.

1

There are 1 answers

5
Pete Houston On

When calling $adapter->api in hybridauth to access Google APIs, you must use the full HTTP URL request.

$answer= $adapter->api()->api('https://www.googleapis.com/plus/v1/people/me');

For other services, such as Facebook, you don't need to

$answer= $adapter->api()->api('/me');

I'm using Laravel 4.2.11 and hybridauth dev-master

Reference: http://hybridauth.sourceforge.net/userguide/tuts/advanced-access-google-api.html