YouTube Data API (v3) 搜索分页,返回“items"空的 [英] YouTube Data API (v3) search pagination, return "items" empty

查看:28
本文介绍了YouTube Data API (v3) 搜索分页,返回“items"空的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用参数的 API 请求:

API request with parameters used:

["items" OK]

part=id

channelId=UCxA5VFvNdlGUTingA9jMu3A

channelId=UCxA5VFvNdlGUTingA9jMu3A

key=[API 密钥]

key=[API KEY]

最大结果=50

pageToken=CIkCEAE

pageToken=CIkCEAE

响应json:

{
 "kind": "youtube#searchListResponse",
 "etag": "\"Bdx4f4ps3xCOOo1WZ91nTLkRZ_c/fRLRzDJR1r68v6VuXm7NWw28YHw\"",
 "nextPageToken": "CIkCEAA",
 "prevPageToken": "CNcBEAE",
 "regionCode": "BR",
 "pageInfo": {
  "totalResults": 335,
  "resultsPerPage": 50
 },
 "items": [
  {
   "kind": "youtube#searchResult",
   "etag": "\"Bdx4f4ps3xCOOo1WZ91nTLkRZ_c/88OMvV6T3kqFzrIZjG-5CBCAyEM\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "gf-L6JkFXjA"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"Bdx4f4ps3xCOOo1WZ91nTLkRZ_c/XNCA6m3Cej2vCZXp6ad_XdO-RRU\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "2wVzOw13t0Q"
  }
  }
 ]
}

返回确定,检查参数是否存在nextPageToken",用于抓取下一页:

Return Ok, check parameter exist "nextPageToken", for capture next page:

新的请求参数:

[items"为空]

part=id

channelId=UCxA5VFvNdlGUTingA9jMu3A

channelId=UCxA5VFvNdlGUTingA9jMu3A

key=[API 密钥]

key=[API KEY]

最大结果=50

pageToken=CIkCEAA

pageToken=CIkCEAA

响应json:

{
 "kind": "youtube#searchListResponse",
 "etag": "\"Bdx4f4ps3xCOOo1WZ91nTLkRZ_c/SgHCPDU8UCvUHeC9Mc-IXFn8mrA\"",
 "nextPageToken": "CLsCEAA",
 "prevPageToken": "CIkCEAE",
 "regionCode": "BR",
 "pageInfo": {
  "totalResults": 335,
  "resultsPerPage": 50
 },
 "items": []
}

在线测试developers.google.com:

Online test developers.google.com:

"items" OK -> https://developers.google.com/youtube/v3/docs/search/list?apix_params={%22part%22:%22id%22,%22channelId%22:%22UCxA5VFvNdlGUTingA9jMu3A%22,%22maxResults%22:50,%22pageToken%22:%22CIkCEAE%22}

"items" Empty -> https://developers.google.com/youtube/v3/docs/search/list?apix_params={%22part%22:%22id%22,%22channelId%22:%22UCxA5VFvNdlGUTingA9jMu3A%22,%22maxResults%22:50,%22pageToken%22:%22CIkCEAA%22}

*** 凭据未使用 Google OAuth 2.0

*** Credentials not used Google OAuth 2.0

推荐答案

YouTube 官方文档在其页面中的演示功能可能会出错.

It might happen something wrong with YouTube official documentation's demo feature in their page.

如果您在 Google API 资源管理器中尝试相同的请求,您将获得下一页/上一页中的项目.

If you try the same request in Google API explorer, you'll get the items in the next/previous pages.

N.B 我遇到过类似的情况,在 YouTube 的官方文档页面不起作用,但是,通过在Google 数据 API,它按预期工作.

N.B I have face similar situations where in the YouTube's official documentation page does not work, but, by testing the same request in Google Data API, it works as expected.

我的建议是,下次遇到类似情况时,请尝试以下这些地方:

My advice is, next time you face a similar situation, try in these places:

  • 在 YouTube 官方 deocumentation 页面中测试您的请求.
  • 在 Google API Explorer 中测试您的请求.
  • 在您的网站、API、页面等中测试您的请求.

示例 - 您请求的第 1 页使用给定的 channel_id UCxA5VFvNdlGUTingA9jMu3A.

Example - page 1 of you request using the given channel_id UCxA5VFvNdlGUTingA9jMu3A.

  • 网址:https://www.googleapis.com/youtube/v3/search?part=id%2C+snippet&channelId=UCxA5VFvNdlGUTingA9jMu3A&maxResults=50&fields=items(id%2Csnippet(channelId%)2CchannelTitle%2Cdescription%2CpublishedAt%2Ctitle))%2Ckind%2CnextPageToken%2CpageInfo%2CprevPageToken%2CregionCode%2CtokenPagination&key={YOUR_API_KEY}
  • 第 1 页 - Google API Explorer 中的链接演示.
  • 第 1 页的结果:
{
 "kind": "youtube#searchListResponse",
 "nextPageToken": "CDIQAA",
 "regionCode": "CO",
 "pageInfo": {
  "totalResults": 335,
  "resultsPerPage": 50
 },
 "items": [
  {
   "id": {
    "kind": "youtube#video",
    "videoId": "Qq5e5EJjeVo"
   },
   "snippet": {
    "publishedAt": "2017-08-06T21:03:15.000Z",
    "channelId": "UCxA5VFvNdlGUTingA9jMu3A",
    "title": "PART3 vs LUDERKING DESGRADIUS FROG VS MACHINE GENEX Yu-gi-oh Duel Links",
    "description": "JOGO 1- https://www.youtube.com/watch?v=PGV0B6WzFv8&t=432s JOGO 2-https://www.youtube.com/watch?v=DWgIJzQCAaU JOGO 3 NO CANAL DO ...",
    "channelTitle": "Miguel Joker Duelinks"
   }
  },
  {
   "id": {
    "kind": "youtube#video",
    "videoId": "Mw-OO_OVIcE"
   },
   "snippet": {
    "publishedAt": "2018-07-08T17:29:53.000Z",
    "channelId": "UCxA5VFvNdlGUTingA9jMu3A",
    "title": "ANALISE NOVO PACK/ ANALISING NEW PACK Yu-gi-oh Duel Links",
    "description": "LINK DO LOOTS/SUPER CHAT GRATIS-https://loots.com/en/tip-jars/migueljoker LINK DO NOSSO DISCORD/OUR FREE DISCORD https://discord.gg/ycdzdsD ...",
    "channelTitle": "Miguel Joker Duelinks"
   }
  },
  {
   "id": {
    "kind": "youtube#video",
    "videoId": "zYWvmqyqj3k"
   },
   "snippet": {
    "publishedAt": "2019-04-03T13:53:33.000Z",
    "channelId": "UCxA5VFvNdlGUTingA9jMu3A",
    "title": "Tudo Sobre Misstiming!! Nao perca para Ag Nem Yubel!! Yu-gi-oh Duel Links",
    "description": "Ajude o Canal com Paypal- migueljokerduelinks@gmail.com Manahen Canal ...",
    "channelTitle": "Miguel Joker Duelinks"
   }
  },
  {
   "id": {
    "kind": "youtube#video",
    "videoId": "HMlCUz25NsU"
   },
   "snippet": {
    "publishedAt": "2019-02-16T03:08:45.000Z",
    "channelId": "UCxA5VFvNdlGUTingA9jMu3A",
    "title": "TOP 1 KC GLOBAL/ Back to Worlds? De Volta ao Mundial? Yu-gi-oh Duel Links",
    "description": "Pagina Facebook- https://www.facebook.com/migueljokerduelinks/ Latino America- https://www.facebook.com/groups/340304503003946/ LINK DO ...",
    "channelTitle": "Miguel Joker Duelinks"
   }
  },
  [more videos here...],
 ]
}

<小时>

  • URL - 第 2 页(使用 pageToken):https://www.googleapis.com/youtube/v3/search?part=id%2C+snippet&channelId=UCxA5VFvNdlGUTingA9jMu3A&maxResults=50&fields=items(id%2Csnippet(channelId%2CchannelTitle%2Cdescription%2CpublishedAt%2Ctitle))%2Ckind%2CnextPage%KeyInfoKey%2CKind%2CnextPage%2A1000000000000000000000000000000000000000000000000000000000000000000000000个
  • 第 2 页 - Google API Explorer 中的链接演示.
  • 第 2 页的结果:
  • {
     "kind": "youtube#searchListResponse",
     "nextPageToken": "CGQQAA",
     "prevPageToken": "CDIQAQ",
     "regionCode": "CO",
     "pageInfo": {
      "totalResults": 335,
      "resultsPerPage": 50
     },
     "items": [
      {
       "id": {
        "kind": "youtube#video",
        "videoId": "LEMjPqqWvy8"
       },
       "snippet": {
        "publishedAt": "2019-05-28T10:57:47.000Z",
        "channelId": "UCxA5VFvNdlGUTingA9jMu3A",
        "title": "Six Samurai Ainda Forte!! Yu-gi-oh Duel Links",
        "description": "Ajude o Canal com Paypal- migueljokerduelinks@gmail.com Manahen Canal ...",
        "channelTitle": "Miguel Joker Duelinks"
       }
      },
      {
       "id": {
        "kind": "youtube#video",
        "videoId": "UZXQa3SSy5M"
       },
       "snippet": {
        "publishedAt": "2019-02-22T23:13:05.000Z",
        "channelId": "UCxA5VFvNdlGUTingA9jMu3A",
        "title": "Novo Deck Fenix Bom ou Bosta? New Fenix is it worth it?Yu-gi-oh Duel Links",
        "description": "Pagina Facebook- https://www.facebook.com/migueljokerduelinks/ Latino America- https://www.facebook.com/groups/340304503003946/ LINK DO ...",
        "channelTitle": "Miguel Joker Duelinks"
       }
      },
      {
       "id": {
        "kind": "youtube#video",
        "videoId": "lNDxWeFgOYI"
       },
       "snippet": {
        "publishedAt": "2019-04-06T15:13:45.000Z",
        "channelId": "UCxA5VFvNdlGUTingA9jMu3A",
        "title": "Melhor Counter de Six Sams!! Best Six Sam  Counter!! Yu-gi-oh Duel Links",
        "description": "Ajude o Canal com Paypal- migueljokerduelinks@gmail.com Manahen Canal ...",
        "channelTitle": "Miguel Joker Duelinks"
       }
      },
      {
       "id": {
        "kind": "youtube#video",
        "videoId": "OP9JTktNEhg"
       },
       "snippet": {
        "publishedAt": "2019-03-02T01:03:24.000Z",
        "channelId": "UCxA5VFvNdlGUTingA9jMu3A",
        "title": "Last  Gamble Cancer Kog Dia1!! 100% Vitoria vs Koaki!! Yu-gi-oh Duel Links",
        "description": "AJ- CANAL https://www.youtube.com/channel/UCZaEOV0fMJBEamZ8K-jPE3A Pagina Facebook- https://www.facebook.com/migueljokerduelinks/ Latino ...",
        "channelTitle": "Miguel Joker Duelinks"
       }
      },
      [more videos here...],
     ]
    }
    

    这篇关于YouTube Data API (v3) 搜索分页,返回“items"空的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆