I am working on a restful API using PHP, this API will be used by a mobile application(iOS & Android) and I am trying to implement Google API login and authorize mobile users to login and use the app.
Here the flow I am trying to achieve :
- User login via mobile app
- User get an access token and send it to the server
- the server fetch the user info on the behalve of the user, using the access_token
I am trying to set the accessToken like this :
$client = new \Google_Client();
$client->setApplicationName(APP_NAME);
$client->setClientId(GOOGLE_APP_ID);
$client->setClientSecret(GOOGLE_APP_SECRET);
$client->setDeveloperKey('');
//set google scopes
$client->setScopes(GOOGLE_USER_PROFILE_SCOPE);
$client->setAccessType('offline');
$client->setAccessToken($accessToken);
$googleOauth2 = new \Google_Service_Oauth2($client);
var_dump($googleOauth2->userinfo_v2_me->get());
For some reason I have an error from the API client
Undefined index: expires_in
I am expecting to get only the access_token as param from Mobile APPs is it possible to get user information this way or I should get the JSON object which contains expires_in as well? I am I doing something wrong and is it possible to do it this way ? Any help or suggestion are well appreciated.