I'm sure there is data, but the YouTube Analytics API returns an empty row

Viewed 39

I copied the code that successfully returns the correct data.

This is my code.

import os
import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors
scopes = ["https://www.googleapis.com/auth/youtube.readonly"]
client_secrets_file = client_secret_xxxxxxx.googleusercontent.com.json"

# Disable OAuthlib's HTTPS verification when running locally.
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"

# Get credentials and create an API client
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(client_secrets_file, scopes)
credentials = flow.run_console()
youtube_analytics = googleapiclient.discovery.build('youtubeAnalytics', 'v2', credentials=credentials)

def main():
    request = youtube_analytics.reports().query(
        startDate='2022-06-26', 
        endDate='2022-06-30',
        ids='channel==MINE',
        dimensions= 'day', 
        metrics= 'views',
    )
    response = request.execute()
    print(response['rows'])

if __name__ == "__main__":
    main()

My channel has 5 views on 2022-06-28.

My YouTube Studio also can see the data.

I expected it will return

[['2022-06-26', 0], ['2022-06-27', 0], ['2022-06-28', 5], ['2022-06-29', 0], ['2022-06-30', 0]]

But it only returned

[]

I found a lot of people have the same problem

Is it possible that this is an issue with the API itself?

0 Answers
Related