我正在尝试使用 PHP 中的 YouTube API 检索频道成员列表。
我拥有所有必要的凭据,例如客户端 ID 和 API 密钥,并且我能够成功进行身份验证。
我还被授予以下范围:
“
https://www.googleapis.com/auth/youtube.channel-memberships.creator
”https://www.googleapis.com/auth/youtube.readonly
”这是我使用的代码:
$client = new Google_Client();
$client->setAccessToken($access_token);
$youtube = new Google_Service_YouTube($client);
$members = $youtube->members->listMembers('snippet');
但是,当我运行此 PHP 代码时,我收到错误代码 403,并显示以下错误消息:
“禁止访问。请求可能未得到适当授权。”
我已经仔细检查过我是否拥有所有必要的凭据和范围,并且身份验证成功。
我正在构建的应用程序将由我独家使用。
我试图从中检索成员列表的 YouTube 频道是我的。
任何人都可以深入了解为什么我可能会收到此错误消息,以及如何解决它?
预先感谢您提供的任何帮助。
编辑:
经过大量研究,我注意到此页面中的这段话:注意:此端点仅供个人创作者使用 请求他们自己的、支持频道会员的 YouTube 频道。 联系您的 Google 或 YouTube 代表以请求访问权限。
所以,我现在的问题是:
如何联系 Google 或 YouTube 代表请求访问权限?
@ilias_gr
尝试以下 PHP 代码参考。
$client = new Google_Client();
$client->setAccessToken($access_token);
// Create a YouTube service instance
$youtube = new Google_Service_YouTube($client);
// Define the request parameters
$params = array(
'part' => 'snippet',
'filter' => 'subscriber', // optional: specify 'subscriber' or 'owner' to filter by membership type
'maxResults' => 50, // optional: specify the maximum number of results per page
'channelId' => 'YOUR_CHANNEL_ID', // replace with your actual channel ID
);
// Make the API request
$response = $youtube->members->listMembers($params);
// Extract the list of members from the response
$members = $response->getItems();