access token

199 views
Skip to first unread message

Mario Rossi

unread,
Feb 2, 2017, 12:15:24 PM2/2/17
to AdWords API Forum
hi 

i get PHP Fatal error:  Uncaught exception 'LogicException' with message 'refresh token must be passed in or set as part of setAccessToken' when trying to access my account whith this script.

require_once 'src/Google/autoload.php'; 
require_once 'Mybusiness.php';  
  
define('APPLICATION_NAME', 'google_api');
define('CREDENTIALS_PATH', 'credentials.json');
define('CLIENT_SECRET_PATH', 'client_secret2.json');

$redirect_uri = 'urn:ietf:wg:oauth:2.0:oob';

$client = new Google_Client();
$client->setApplicationName(APPLICATION_NAME);
$client->setAuthConfigFile(CLIENT_SECRET_PATH);
$client->setRedirectUri($redirect_uri);
$client->setAccessType("offline");
$client->setApprovalPrompt("force"); 

$mybusinessService = new Google_Service_Mybusiness($client);

$credentialsPath = CREDENTIALS_PATH;

if (file_exists($credentialsPath)) {
  $accessToken = file_get_contents($credentialsPath);
  $client->setAccessToken($accessToken);
  if ($client->isAccessTokenExpired()) {
    $client->refreshToken($client->getRefreshToken());
    file_put_contents($credentialsPath, $client->getAccessToken());
  }
} else {
  $authUrl = $client->createAuthUrl();
}

$rslt_data=$mybusinessService->accounts_locations->listAccountsLocations('accounts/xxxxxxxxxxxxxxxxxxxxx');

echo $rslt_data;

thx for the help


Sreelakshmi Sasidharan (AdWords API Team)

unread,
Feb 2, 2017, 2:15:29 PM2/2/17
to AdWords API Forum
Hi, 

I see that you are using the Google My Business API. This forum is exclusively for questions related to the AdWords API. 

You could try posting your question on the Google My Business API support forum. 

Thanks,
Sreelakshmi, AdWords API Team
Reply all
Reply to author
Forward
0 new messages