1

I am currently writing a python script to pull information from YouTube Analytics API for a list of separate YouTube channels. The output would be, for example, count video views for each YouTube channel in last month.

My initial idea was to ask each of the YouTube account owners to create a YouTube Analytics app in their console.cloud.google, create a Project, enable the youTube Analytics API, generate an API key and specify that it is needed for the YouTube Analytics API.

I'm testing with one account and if I try to run the script using the API Key generated with the process described above and authenticating like this:

def get_service():
    return build('youtubeAnalytics', 'v2', developerKey=API_KEY)

it fails with a HttpError 401 Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.

I am not sure if I have done something wrong in creating the API key, or if instead the YouTube Analytics API requires Oauth2 authentication. If the latter is the case, then I am surprised that google console lets you to go all the way and generate API keys and specify that they are needed for the YouTube Analytics API, only for you to find out that you can't use it.

So my question is: do I have to use Oauth2 for YouTube Analytics API or can I use the API key? I'm trying to read data from "my own" account, so why do I need to manually authorise my own app?

2 Answers 2

6

Ok I found out that it is not possible to use YouTube Analytics API without OAuth 2.0 authentication. The Google docs and the Google console are very confusing in my opinion as they respectively allow you to create API keys specific for YouTube Analytics API and describe API keys as a possible way to authenticate (only to tell you after that, that all methods require OAuth2.0).

I'm still unclear on how to setup YouTube Analytics API authentication for a command-line python script that does not require users to give manually consent every time the script runs.

I will open a separate question for that.

Sign up to request clarification or add additional context in comments.

3 Comments

How did you get it to work? I'm facing the same problem. Before this, I could retrieve the data with the user's access token
I have asked the client to provide their client secret, then I run a script that opens the OAuth 2.0 authentication page. I send them the link to the page from which they authenticate. After they authenticate they send me back a token which I paste in the command line and I get authenticated. The script contains a logic to also store the refresh token so that this process involving the client authenticating via browser should be required only once.
Wow. It would be hard for me because I can get hundreds or thousands of users. Thanks
0

Set key parameter. You can read data with api key. It's simple.

http -v 'https://www.googleapis.com/youtube/v3/playlistItems?playlistId={playlistId}&part=id,snippet,contentDetails,status&key={api_key}&max_results=10'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.