刷新令牌這裏是我的PHP腳本RefreshToken.php
無法從谷歌API的OAuth2
<?php
$url = 'https://accounts.google.com/o/oauth2/token';
$post_data = array(
'code' => 'xxxxxxxx',
'client_id' => 'xxxxxxxxxxx',
'client_secret' => 'xxxxxxxxxxxxx',
'redirect_uri' => 'http://localhost/googleapi/AuthenticationCode.php',
'grant_type' => 'authorization_code',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$token = json_decode($result);
echo $token->refresh_token . "\n";
?>
運行PHP CLI
PHP -q RefreshToken.php
PHP公告:未定義的屬性:stdClass的: :第20行的/var/www/googleapi/RefreshToken.php中的$ refresh_token
請在$結果的回聲......我的猜測是,$結果是一個數組不是對象... –