Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Youtube Data API - How to avoid Google OAuth redirect URL authorization

Requirement: I am trying to upload videos to my Youtube channel through Youtube Data API for Java. The request is sent from a war file hosted on tomcat container.My application is not for external users and I only use it to upload my own generated videos. With the help of the api documentation and sample youtube code snippets, I have successfully managed to post video on youtube.

Problem: The issue is that whenever I try to run the code, I get prompted for

Please open the following address in your browser: https://accounts.google.com/o/oauth2/auth?client_id=&redirect_uri=http://localhost:8080/Callback&response_type=code&scope=https://www.googleapis.com/auth/youtube.upload


Since I run this code on a remote server, it is not possible for me to always open this URL on the browser. Since I have registered my web app in Google Console, and got a pair of Client ID and Secret and a JSON file, so Youtube must allow me to publish videos by default to atleast my channel, isin't it?

I have used the Auth.java file(provided in youtube java code samples) and the following code is where this thing happens.

    // Authorize.
    return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("[email protected]");

LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();

Please help here as this is really eating up a lot of my development time.

like image 419
ayan_2587 Avatar asked Jul 07 '15 06:07

ayan_2587


People also ask

What is Google OAuth redirect URI?

The redirect URIs are the endpoints to which the OAuth 2.0 server can send responses. These endpoints must adhere to Google's validation rules. For testing, you can specify URIs that refer to the local machine, such as http://localhost:8080 .

What is a OAuth redirect URL?

The redirect URL is the endpoint for your application or web page that processes the seller authorization response and manages the seller's OAuth tokens. You need to add this URL to your application using the Developer Dashboard.

How do I auth YouTube API?

First, set up your project, website, or app and then get a YouTube API key. This key will let you access YouTube's Live Streaming API. Don't forget to register your app with Google so that your API requests are successfully authenticated.

How does OAuth redirect work?

If the request is valid and the user grants the authorization request, the authorization server generates an authorization code and redirects the user back to the application, adding the authorization code and the application's “state” value to the redirect URL.


1 Answers

You should only need to authenticate your code once. When your code is authenticated you get a refresh token back. the refresh token will then allow you to get a new access token the next time your code runs.

There is no service account authentication for the YouTube api. Your code has to be authenticated by you the first time in order to get that refresh token.

I am not a java programmer but from a quick check of the documentation it looks quite similar to what I do in.net. You need to create a datastore to to store the first refreshh token then you should be able to run your code in the future with out needing to authenticate it again.

like image 116
DaImTo Avatar answered Sep 20 '22 09:09

DaImTo