I am working with google api(Rest Api) in php, I just want whenever any user send "access_token/token" then i want to validate and get userinfo,How can i do this ?
I tried with following code but not working for me,showing me always url in my postman,Where i am wrong ?
<?php
$google_client->authenticate($_GET['code']);
$client = new Google_Client();
$google_client = new Google_Client();
$google_client->setClientId('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com'); //Define your ClientID
$google_client->setClientSecret('xxxxxxxxxxxxxxxxxxxxx'); //Define your Client Secret Key
$google_client->setRedirectUri('xxxxxxxxxxxx'); //Define your Redirect Uri
$google_client->addScope('email');
$google_client->addScope('profile');
$objOAuthService = new Google_Service_Oauth2($google_client);
$getAccesToken = $google_client->getAccessToken();
$getRefreshToken = $google_client->getRefreshToken();
$google_client->setAccessToken($token['access_token']);
$objOAuthService = new Google_Service_Oauth2($google_client);
if($google_client->getAccessToken()) {
$userData = $objOAuthService->userinfo->get();
if(!empty($userData))
{
$outputjson['user_data'] = $userData;
$outputjson['access_token'] = $google_client->getAccessToken();
}else{
$outputjson['login_url'] = $google_client->createAuthUrl();
}
}