0

I have a content owner account, and I used Google's API Explorer to figure out the query that I need to send. My problem now is that I can't figure out how to send that same query programmatically via Python. I have generated oauth credentials as well as an API key - for an installed application -, so I also have a client_secrets.json file. What I can't figure out is how do I use this information to get through and send my query. There's a lot of talk of "scope" in the other questions I've reviewed, but I'm confused about how I need to include that in my request.

I tried passing the contents of the client secrets file as headers in my request, I also tried just appending the simple API key to the end of the request, no dice. Also looked at several questions on here, but they either aren't relevant to content owners, or are about getting the right query itself rather than the authentication portion. Any help would be appreciated. Thanks in advance!

Examples:

yt_headers = {"client_id": CLIENT_ID,
"client_secret":CLIENT_SECRET,
"redirect_uris": REDIRECT_URIS,
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token"}

query_string = 'https://www.googleapis.com/youtube/analytics/v1/reports?ids=contentOwner%3D%3DCONTENT_ID&start-date=2015-09-28&end-date=2015-11-05&metrics=views&dimensions=insightTrafficSourceType&filters=video%3D%3DVIDEO_ID&fields=rows'
api_request = http.request('GET', query_string, headers=yt_headers)
NeonBlueHair
  • 1,139
  • 2
  • 9
  • 22

1 Answers1

0

As mentioned in YouTube Analytics API: Content Owner Reports,

To retrieve a content owner report, call the API's reports.query method and set the ids parameter value in the API request to contentOwner==OWNER_NAME, where OWNER_NAME specifies the content owner's ID.

In Reports: Query, you may send your HTTP request with the following format:

GET https://www.googleapis.com/youtube/analytics/v1/reports

Please note that YouTube Analytics API requests must be authorized. Aside from that, you can also add query parameters, such as dimensions, filters, and sorting instructions.

This related SO post - YouTube Analytics API - Content owner reports might also help.

Community
  • 1
  • 1
Teyam
  • 7,686
  • 3
  • 15
  • 22