私はYoutubeのAPIにアクセスするために以前はGoogleアカウントに問題がありました。そこで私は新しい新鮮なGmailアカウント&を作成してそれを稼働させました。 1時間のような後だけでなく。リフレッシュトークンが爽やかではないことがわかった。どうしてか分かりません。これは、私がYoutubeサービスを使用してもはや没収しなければならないように思えるので、イライラしています。Youtube APIはアクセストークンを更新できません
これは私のコードです:おそらく私は何か間違っています。
$client = new Google_Client();
$client->setClientId($OAUTH2_CLIENT_ID);
$client->setClientSecret($OAUTH2_CLIENT_SECRET);
$client->setScopes('https://www.googleapis.com/auth/youtube');
$redirect = filter_var('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'],
FILTER_SANITIZE_URL);
$client->setRedirectUri($redirect);
$client->setAccessType('offline');
$client->setApprovalPrompt('force'); // this line is important when you revoke permission from your app, it will prompt google approval dialogue box forcefully to user to grant offline access
// Define an object that will be used to make all API requests.
$youtube = new Google_Service_YouTube($client);
// Check if an auth token exists for the required scopes
$tokenSessionKey = 'token-' . $client->prepareScopes();
$_SESSION[$tokenSessionKey] = $manually_stored_token; //$client->getAccessToken();
if (isset($_SESSION[$tokenSessionKey])) {
$client->setAccessToken($_SESSION[$tokenSessionKey]);
}
// Check to ensure that the access token was successfully acquired.
if($client->isAccessTokenExpired()) {
$client->refreshToken($refresh_token);
if(!$client->isAccessTokenExpired()) {
// do something
} else {
// refresh access token not granted
}
} else if ($client->getAccessToken()) {
// do something
} else {
// do something
}
私は、「サインイン&セキュリティ」、Googleアカウントへの許可されたアクセスのための下で、私はまだ許可を持って、自分のアカウントhttps://myaccount.google.com/u/0/securityをチェックします。だから私はなぜ私のトークンをリフレッシュしないのか分からない。
クライアントライブラリは、アクセストークンをリフレッシュする必要がある場合にのみ使用してください。あなたはそれをどう思いますか? – DaImTo
トークンが期限切れになってからリフレッシュしようとするときにブレークポイントを設定するので、私は間違いなく爽やかではないことを知っています。これはちょうど停止するまで、一週間のように働いていた。私は何も変わらなかった、少なくとも私が知っている! –