Issue with Google-API-PHP Client, getting error when running the quick start script

前端 未结 2 1176
我寻月下人不归
我寻月下人不归 2020-12-19 08:17

I am facing an issue with quickstart php script here: https://developers.google.com/drive/v2/web/quickstart/php

When I run the script first time, it executes perfect

2条回答
  •  清酒与你
    2020-12-19 08:44

    Google has updated their PHP Quickstart, with an improved method to handle this:

    // Exchange authorization code for an access token.
    $accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
    $client->setAccessToken($accessToken);
    
    // Refresh the token if it's expired.
    if ($client->isAccessTokenExpired()) {
    $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
    file_put_contents($credentialsPath, json_encode($client->getAccessToken()));
    }
    

提交回复
热议问题