YouTube API订阅插入始终会返回错误

时间:2018-01-08 06:07:14

标签: google-api youtube-api youtube-data-api

如何为经过身份验证的用户的频道添加订阅

https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&key={YOUR_API_KEY}

请求参数: -

{ 
"0":
 {  "name": " <code>snippet.resourceId.kind</code>",  "value": "youtube#channel" },

"1": {  "name": " <code>snippet.resourceId.channelId</code>",  "value": "UC_x5XG1OV2P6uZZ5FSM9Ttw" }

}

响应参数: -

{
 "error":
 {  "errors":
 [   {    "domain": "youtube.subscription",    "reason": "publisherRequired",    "message": "The subscription resource specified in the request must use the <code>snippet.resourceId</code> property to identify the channel that is being subscribed to."   }  ],  "code": 400,  "message": "The subscription resource specified in the request must use the <code>snippet.resourceId</code> property to identify the channel that is being subscribed to." }
            }

2 个答案:

答案 0 :(得分:1)

这是Youtube api中的一个错误。这可以通过检查api explorer here来验证。

POST https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&key={YOUR_API_KEY}

{
 "0": {
  "name": "snippet.resourceId",
  "value": "youtube#channel"
 },
 "1": {
  "name": "snippet.resourceId",
  "value": "UC_x5XG1OV2P6uZZ5FSM9Ttw"
 }
}

回复

{
 "error": {
  "errors": [
   {
    "domain": "youtube.subscription",
    "reason": "publisherRequired",
    "message": "The subscription resource specified in the request must use the <code>snippet.resourceId</code> property to identify the channel that is being subscribed to."
   }
  ],
  "code": 400,
  "message": "The subscription resource specified in the request must use the <code>snippet.resourceId</code> property to identify the channel that is being subscribed to."
 }
}

此问题有一个issue request,团队已被ping。

答案 1 :(得分:-1)

Link of Youtube Data API (V3), you can try here

it's the image example in "try this API" of how i do

POST https://www.googleapis.com/youtube/v3/subscriptions?part=snippet HTTP/1.1
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json
Content-Type: application/json

{
  "snippet": {
  "resourceId": {
  "kind": "youtube#channel",
  "channelId": "UCUK0HBIBWgM2c4vsPhkYY4w"
    }
  }
}