Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP致命错误:未捕获的InvalidArgumentException:vendor/google/apiclient/src/google/Client中的令牌格式无效。PHP:423_Api_Google Sheets Api - Fatal编程技术网

PHP致命错误:未捕获的InvalidArgumentException:vendor/google/apiclient/src/google/Client中的令牌格式无效。PHP:423

PHP致命错误:未捕获的InvalidArgumentException:vendor/google/apiclient/src/google/Client中的令牌格式无效。PHP:423,api,google-sheets-api,Api,Google Sheets Api,下面是用于编辑谷歌电子表格的代码,但我们遇到了与访问令牌相关的问题,请告诉我是否有人对此问题有解决方案。对于Outh客户端id,我们有以下说明: [29-Sep-2019 04:10:36 UTC]PHP致命错误:未捕获的无效argumentException:/home/help4dl9/public_html/doamin.com/wp content/themes/Twenty十九/google sheet/vendor/google/apiclient/src/google/Clien

下面是用于编辑谷歌电子表格的代码,但我们遇到了与访问令牌相关的问题,请告诉我是否有人对此问题有解决方案。对于Outh客户端id,我们有以下说明:

[29-Sep-2019 04:10:36 UTC]PHP致命错误:未捕获的无效argumentException:/home/help4dl9/public_html/doamin.com/wp content/themes/Twenty十九/google sheet/vendor/google/apiclient/src/google/Client.PHP:423中的无效令牌格式

下面是getClient函数:


function getClient()
{

$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];

$client = new Google_Client();

$client->setApplicationName('APP NAME');

$client->setScopes( 'https://www.googleapis.com/auth/spreadsheets' );

$client->setAuthConfig( __DIR__ . '/credentials.json' );

$client->setAccessType('offline');

$client->setPrompt('select_account consent');

// Load previously authorized token from a file, if it exists.
// The file token.json stores the user's access and refresh tokens, and is
// created automatically when the authorization flow completes for the first
// time.
$tokenPath = __DIR__ . '/token.json';
if (file_exists($tokenPath)) {
    $accessToken = json_decode(file_get_contents($tokenPath), true);
    $client->setAccessToken($accessToken);
}
// If there is no previous token or it's expired.
if ($client->isAccessTokenExpired()) {
    // Refresh the token if possible, else fetch a new one.
    if ($client->getRefreshToken()) {
        $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
        $authObj = $client->getAccessToken();
        if(array_key_exists("access_token",$authObj)) {
            update_field( 'authentication_code', $authObj['access_token'],'option' ); // Save Token in Theme Option
        }
    } else {
        // Request authorization from the user.
        $authCode = get_field('authentication_code','option');
        // Exchange authorization code for an access token.
        $accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
        $client->setAccessToken($accessToken);
        // Check to see if there was an error.
        if (array_key_exists('error', $accessToken)) {
            throw new Exception(join(', ', $accessToken));
        }
    }
    // Save the token to a file.
    if (!file_exists(dirname($tokenPath))) {
        mkdir(dirname($tokenPath), 0700, true);
    }
    file_put_contents($tokenPath, json_encode($client->getAccessToken()));
}
return $client;
}```




请按照以下说明操作,而不使用
$redirect\u uri
get\u field