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

1

8

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.

Thankless answered 7/7, 2015 at 6:47 Comment(2)
could you update how did you get a permanant access token?Theroid
need also a solution for this, can u share the code. thank youButtonwood
T
2

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.

Thanhthank answered 7/7, 2015 at 7:5 Comment(3)
Thankyou for giving me a pointer, read the links suggested by you and got to know how to get a permanant access token.Thankless
i encounter same issue as yours, i cant open a browser in remote box, how did u get permannent token and how you store it?Buttonwood
There is no such thing as a permanant token you can get a refresh token which will allow you to get a new access token when ever needed. Refresh tokens are valid as long as they are not revoiked by the user.Thanhthank

© 2022 - 2024 — McMap. All rights reserved.