Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3832

Can't get next page when using search in youtube data api v3

$
0
0

I tried to get a list of videos using youtube data api v3 search and could not get the data after page 2.The query result itself seems to have the following number of data, paging through every 50 results.total results 70225The first page has 50 results, but when I try to retrieve the second page, there are no results.Do I need to do anything special to get the second and subsequent pages?

The code is as follows

Environment Construction#### youtubeAPI用環境構築###RUN pip install --upgrade pip RUN pip install sixRUN pip install pandasRUN pip install requestsRUN pip install --user poetryRUN pip install packagingRUN pip install --upgrade db_dtypes#### GCP関連環境構築###RUN pip install google-api-python-clientRUN pip install google-cloud-logging
# python3.1from googleapiclient.discovery import buildyoutube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey=YOUTUBE_API_KEY)def get_video_info(part, q, order, type, num, data):    #print('part = '+ part)    #print('q = '+ q)    #print('oeder = '+ order)    #print('type = '+ type)    search_list = []    for i in range(num):      print(i)      if i == 0:        search_query = youtube.search().list(          part=part,          q=q,          order=order,          type=type,          publishedAfter=beforeWeekDay,          maxResults=50,# maxResults→5~50          regionCode='JP',          videoDuration='short'          )      else:        pageInfo = api_response["pageInfo"]        print('total results '+ str(pageInfo['totalResults']))        search_query = youtube.search().list_next(          search_query,          api_response,        )      try:        print('do search')        api_response = search_query.execute()      except Exception as e:        print(e)        print('件数不足なためyoutube APIコール失敗「想定どおりの挙動」')        break

What we have triedChange the content of the query and the number of results retrieved per page.When we changed the number of results to 50 or 20 per page and used the same query to retrieve data, we were only able to retrieve data up to page 1, and when we turned to page 2, the search results were zero.


Viewing all articles
Browse latest Browse all 3832

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>