YouTube Api:snippet.live_chat_id是必需的
问题描述:
我一直在努力与youtube很多。 问题是,我做了我自己的PHP curl脚本,它应该连接到YouTube的api并发送一条即时消息到我目前的流。YouTube Api:snippet.live_chat_id是必需的
我很接近完成这个问题,但只有这1个最后部分阻止了我。
我目前使用的脚本是:
$data = array("snippet" => ["type" => 'textMessageEvent', 'textMessageDetails' => ['messageText' => '<3']], 'livechatid' => '{{livechatid_here}}');
$data_string = json_encode($data);
$ch = curl_init('https://www.googleapis.com/youtube/v3/liveChat/messages?part=snippet&fields=authorDetails%2Ckind%2Csnippet&key={{Here is my key}}');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
'Authorization: Bearer {{access_key}} ')
);
$result = curl_exec($ch);
dd($result);
但IM不断收到以下错误:
"code": 400,
"message": "snippet.live_chat_id is required"\n
所以我所做的就是我改变 'livechatid' 到:
- liveChatId(API告诉我)
- live_Chat_Id
- livechatid
- snippet.livechatid
- snippet.liveChatId
- snippet.live_chat_id
而且没有一次成功。 有谁知道我该如何解决这个问题?
因为我从上面的代码中删除了我的密钥和access_tokens。
我也尝试将它们添加到标题,但我仍然一次又一次得到相同的错误。
有谁知道我能如何解决这个问题?
答
将liveChatId
的snippet
领域内:
$data = array("snippet" => [
"type" => 'textMessageEvent',
'textMessageDetails' => ['messageText' => '<3'],
'liveChatId' => 'YOUR_LIVE_CHAT_ID'
]);
$data_string = json_encode($data);