YouTube API v3 with OAuth2: Update and Uninstall Failure with "Inadequate Resolution" Error

I am trying to use update and delete videos using the YouTube v3 API with OAuth2 for authentication through the google-api-client (0.6.4) Ruby google-api-client (0.6.4) . However, when I try to do one of these two actions, I see the following error message:

 Google::APIClient::ClientError: Insufficient Permission 

Here's the strange thing: Using the same authentication procedure as with update and delete , I can insert (upload) successfully, no problem! Therefore, I do not think this is a problem with setting my authentication, but somewhere else in my code.

My read-write scope always the same for any of these actions:

 https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtube.upload 

And according to the API documentation, this set of space-limited areas should cover insert , update and delete actions.

My client_id , client_secret , refresh_token always the same for all these actions - so this also cannot be a problem, can it? Please note that my program automatically receives a new access_token when it expires, therefore, again, I do not believe that this is the problem.

For comparison, here is what my insert (upload) code ( works ) looks like:

 # Auth stuff, then... @client.execute!( :api_method => @youtube.videos.insert, :body_object => body, :media => Google::APIClient::UploadIO.new(file_path, 'video/*'), :parameters => { 'uploadType' => 'multipart', :part => body.keys.join(','), } ) 

And here is what my delete code looks like ( this does not work ):

 # Auth stuff, then... @client.execute!( :api_method => @youtube.videos.delete, :parameters => { 'id' => youtube_id, } ) 

What am I missing? Unfortunately, the YouTube API documentation for removal does not contain any examples, so I have nothing to compare. Please let me know if there is additional information that I can provide to make my question more clear.

+6
source share
1 answer

I am sure that all 11 views of this question (at the time of writing) is me, but I am going to post an answer just in case this helps someone in the future:

There were no problems with my code. The problem was that I initially created my refresh_token for this account.

For the uninitiated data APIs, YouTube (v3) does not support the “service accounts” that elsewhere in the Google API ecosystem are the way you usually configure the OAuth2 auth'd client when you are the only client. A workaround is what you need to do manually. Follow these steps:


First go to the Google API Console. There, in the "Access to API" section, you need to "Create a client identifier" for the "installed application". This will give you a Client ID , a Client secret and a Redirect URI (you will need a non- localhost ). Write them down.

Then you need to manually obtain the authorization code by visiting the URL similar to the following in your favorite web browser: when you log in to the same account, you just created the client ID:

 https://accounts.google.com/o/oauth2/auth ?client_id={client_id} &redirect_uri={redirect_uri} &scope={space separated scopes} &response_type=code &access_type=offline 

Of course, you need to enter the client_id , redirect_uri and scope request parameters. In my case, I was mistaken . When I did this manual step, I had to set the scope parameter as:

 https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtube.upload 

But instead, I just did https://www.googleapis.com/auth/youtube.upload , which is not enough to update / delete a video!

Finally, you need to get refresh_token by selecting this URL:

 https://accounts.google.com/o/oauth2/token ?code={authorization_code} &client_id={client_id} &client_secret={client_secret} &redirect_uri={redirect_uri} &grant_type=authorization_code 

And twisting with a command like:

 $ curl https://accounts.google.com/o/oauth2/token -d "code=..." 

This will return a JSON response containing your refresh_token , which is then used to authorize your request programmatically through the Google API.

+13
source

Source: https://habr.com/ru/post/955057/


All Articles