无法使用API​​删除Youtube订阅

时间:2018-08-18 19:21:12

标签: youtube-api youtube-data-api

我具有使用oauth登录的YouTube API的代码设置。登录似乎正常工作。我什至可以看到请求达到我的分析水平。但是,当我运行代码以退订某个频道时,它永远无法在我提供的任何频道ID上运行。应该注意的是,I'm using the exact example from googles dev docs(请参见javascript的“完整示例”选项)...我猜代码是正确的,这是其他一些身份验证/查找问题。


API代码:

 alert("deleting steven!!!!!!");
 buildApiRequest('DELETE',
               '/youtube/v3/subscriptions',
               {'id': 'UCMtFAi84ehTSYSE9XoHefig'}); 

Stock Youtube API代码:

function executeRequest(request) {
    request.execute(function(response) {
      console.log(response);
    });
  }

  function buildApiRequest(requestMethod, path, params, properties) {
    params = removeEmptyParams(params);
    var request;
    if (properties) {
      var resource = createResource(properties);
      request = gapi.client.request({
          'body': resource,
          'method': requestMethod,
          'path': path,
          'params': params
      });
    } else {
      request = gapi.client.request({
          'method': requestMethod,
          'path': path,
          'params': params
      });
    }
    executeRequest(request);
  }

这是错误:

    {
 "error": {
  "errors": [
   {
    "domain": "youtube.subscription",
    "reason": "subscriptionNotFound",
    "message": "The subscription that you are trying to delete cannot be found. Check the value of the requests \u003ccode\u003eid\u003c/code\u003e parameter to ensure that it is correct."
   }
  ],
  "code": 404,
  "message": "The subscription that you are trying to delete cannot be found. Check the value of the requests \u003ccode\u003eid\u003c/code\u003e parameter to ensure that it is correct."
 }
}

1 个答案:

答案 0 :(得分:1)

请记住,您必须发送的ID不是频道ID。这是订阅的ID。 您可以通过发送请求以使用频道检查您的订阅来获取它。例如

请求:

li

回复:

buildApiRequest('GET',
                '/youtube/v3/subscriptions',
                {'forChannelId': 'UCEhZglE9MQ4zTL5ErNXt5mg',
                'mine': 'true',
                'part': 'snippet,contentDetails'});

在响应中使用ID发送退订请求:

{
  "kind": "youtube#subscription",
  "etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/KrR9MNb4Xs1eNjWMxAH-f5ccsos\"",
  "id": "Xmg72z6q83hK2hjx0J4ZwNVcgGz8fu9JCjeHu6eIb3M",
  "snippet": {
    "publishedAt": "2018-09-30T16:51:47.000Z",
    "title": "Rebeca Willett",
    "description": "",
    "resourceId": {
      "kind": "youtube#channel",
      "channelId": "UCEhZglE9MQ4zTL5ErNXt5mg"
    },
    "channelId": "UCWfZYaoFrUOSoHNhCOOqKCQ",
    "thumbnails": {
    ...
}

这里是google docs for getting subscriptions ID