使用 Google API,我希望檢索我從 Youtube 帳戶訂閱的頻道列表。為此,我使用了以下 PHP 庫:https://packagist.org/packages/league/oauth2-client。應用所有必要的信息后,我收到以下錯誤:致命錯誤:未捕獲的 UnexpectedValueException:從授權服務器收到的響應無效。預期的 JSON ....這是我的代碼:<?phprequire 'vendor/autoload.php';$provider = new \League\OAuth2\Client\Provider\GenericProvider([ 'clientId' => 'my_oauth_client_id', // The client ID assigned to you by the provider 'clientSecret' => 'my_oauth_client_secret', // The client password assigned to you by the provider 'redirectUri' => 'http://localhost/oauthytb/index.php', 'urlAuthorize' => 'https://accounts.google.com/o/oauth2/v2/auth', 'urlAccessToken' => 'https://oauth2.googleapis.com/token', 'urlResourceOwnerDetails' => 'https://www.googleapis.com/auth/youtube.readonly']);// If we don't have an authorization code then get oneif (!isset($_GET['code'])) { $options = [ 'scope' => ['https://www.googleapis.com/auth/youtube.readonly'] ]; // Fetch the authorization URL from the provider; this returns the // urlAuthorize option and generates and applies any necessary parameters // (e.g. state). $authorizationUrl = $provider->getAuthorizationUrl($options); // Get the state generated for you and store it to the session. $_SESSION['oauth2state'] = $provider->getState(); // Redirect the user to the authorization URL. header('Location: ' . $authorizationUrl); exit;// Check given state against previously stored one to mitigate CSRF attack} elseif (empty($_GET['state']) || (isset($_SESSION['oauth2state']) && $_GET['state'] !== $_SESSION['oauth2state'])) { if (isset($_SESSION['oauth2state'])) { unset($_SESSION['oauth2state']); } exit('Invalid state');}
訂閱列表 YouTube API
慕碼人2483693
2023-09-22 14:47:39