0

So I have been using youtube api to scrape a channel. Everything was working fine until 3 days ago (03/15/2019) when the result isn't sorted anymore. It seems that no matter what I put in the order parameter, the results are all the same. Can anyone tell me why it isn't working? Here's the code snippet:

import re
import os
import json
import MySQLdb
from pytube import YouTube
import urllib
import isodate
import sys

def get_all_video_in_channel(channel_id):
    api_key = '<MY KEY>'
    video_url = 'https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails&id={}&key={}'
    first_url = 'https://www.googleapis.com/youtube/v3/search?key={}&channelId={}&part=snippet,id&order=date&maxResults=50'.format(api_key, channel_id) #order by date but won't work

    res = []
    url = first_url
    while True:
        inp = urllib.urlopen(url)
        resp = json.load(inp)
        vidIds = []
        for jobject in resp['items']:
            if jobject['id']['kind'] == "youtube#video":
                vidIds.append(jobject['id']['videoId'])

        vidreq = urllib.urlopen(video_url.format(",".join(vidIds),api_key))
        vidres = json.load(vidreq)
        for vidjson in vidres['items']:
            res.append(vidjson)
        if (len(res) >= 50):
            break
        try:
            next_page_token = resp['nextPageToken']
            url = first_url + '&pageToken={}'.format(next_page_token)
        except:
            break

    return res

c_id = 'UCycyxZMoPwg9cuRDMyQE7PQ'
episodes = get_all_video_in_channel(c_id)

Edit: I did some more research and people say that the API indeed is not working properly due to Youtube doing something with deleting the New Zealand shooting video and it will soon be working properly again.

Nhat Ton
  • 21
  • 4
  • What's your question here? Maybe "Why isn't it working?" ? Did you consider submitting a bug report to developers? – Viacheslav Shalamov Mar 18 '19 at 19:51
  • @ViacheslavShalamov The thing isn't working here is that the sort parameter. I want to sort the result by date but it isn't sorted by date, in fact, it isn't sorted by anything at all. The weird thing is that it had been working for a long time before it broke. I need some support from Google people and they say this is where I should put the question. – Nhat Ton Mar 18 '19 at 20:19
  • "I need some support from Google people and they say this is where I should put the question" - they are lying :) . It's good to have question here, but what you really need to do is to submit a bug report with proof and examples, so that they can deal with it. – Viacheslav Shalamov Mar 18 '19 at 21:22

1 Answers1

0

I recommend you to see the answer https://stackoverflow.com/a/55220182/8327971. This is a known and acknowledged issue by Google: https://issuetracker.google.com/issues/128673552.

stvar
  • 6,551
  • 2
  • 13
  • 28