2

I have created set of YouTube reporting jobs for a YouTube channel. The jobs were created and run every day as scheduled. However when I go to download the jobs they are all blank.

This is how I authenticate with the API:

def authenticate_from_credentials(API_SERVICE_NAME, API_VERSION):
        youtube_client_id = os.environ['youtube_client_id']
        youtube_client_secret = os.environ['youtube_client_secret']
        youtube_refresh_token = os.environ['youtube_refresh_token']
        credentials = client.OAuth2Credentials(
            access_token=None,
            client_id=youtube_client_id,
            client_secret=youtube_client_secret,
            refresh_token=youtube_refresh_token,
            token_expiry=None,
            token_uri='https://oauth2.googleapis.com/token',
            user_agent=None,
            revoke_uri=None
        )
        youtube_reporting = build(API_SERVICE_NAME, API_VERSION, credentials=credentials)
        return youtube_reporting

This is the method I have been using to create the jobs:

# Call the YouTube Reporting API's jobs.create method to create a job.
def create_reporting_job(youtube_reporting, report_type_id, name):
  # Provide keyword arguments that have values as request parameters.
    reporting_job = youtube_reporting.jobs().create(
        body=dict(
          reportTypeId=report_type_id,
          name=name
        ),
      ).execute()
    print ('Reporting job "%s" created for reporting type "%s" at "%s"'
           % (reporting_job['name'], reporting_job['reportTypeId'],
              reporting_job['createTime']))

I authenticate like this:

youtube_reporting=authenticate_from_credentials('youtubereporting','v1')

And I will create a job like this:

create_reporting_job(youtube_reporting,"channel_combined_a2","Channel Combined a2")

I am not sure what the problem is here. The channel does have content and subscribers so the reports shouldn't be empty. I think there could be an issue with credentials or perhaps the wrong channel is associated with the report since the developer's Google accounts are different than the content owners. But I checked the channels associated with the Oauth credentials I am using and it was the right channel.

Why might my reports be empty and how can I fix this?

Pingu Noot
  • 51
  • 3

1 Answers1

2

I hit the same issue, the problem is that you need to wait several hours for the report to become generated on the backend, at which point re-querying for reports will show results.

There is a subtle mention about this delay on https://developers.google.com/youtube/reporting/v1/reports under Step 3:

The API response to the jobs.create method contains a Job resource, which specifies the ID that uniquely identifies the job. You can start retrieving the report within 48 hours of the time that the job is created, and the first available report will be for the day that you scheduled the job.

This was quite confusing.

Andrew
  • 1,606
  • 1
  • 12
  • 19