Google API refresh token merchant?

44 views Asked by At

I’m writing a code for authorization through Google Merchant, the data is falling, but after 1.5 hours the token expires and the script dies. Is it possible to somehow increase the life of the main token or get a refresh token. I am attaching the code.

Receiving a token

$client = new Google_Client();
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->setAccessType('offline');
$client->setScopes($scopes);

// Initialize the Google Service for Google Merchant Center
$service = new Google_Service_ShoppingContent($client);
$authUrl = $client->createAuthUrl();

$response = array("authUrl" => $authUrl);
header("Content-Type: application/json");
echo json_encode($response);

Second part to start script with token

$client = new Google_Client();
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->addScope(Google_Service_ShoppingContent::CONTENT);


$service = new Google_Service_ShoppingContent($client);
$code = $_POST['code'];

$accessToken = $client->fetchAccessTokenWithAuthCode($code);

$client->setAccessToken($accessToken);
0

There are 0 answers