'Youtube video upload library (google-api-services) provides a new port every-time (which cannot be authorised)

I am trying to upload a video on youtube using NetHttpTransport.java class (as defined in the example created by google). The problem is that everytime I get a new port from GoogleNetHttpTransport.newTrustedTransport(). So the URL that is making a hit changes on every call.

For example-
URL1 = http://localhost:57005/Callback
URL2 = http://localhost:57296/Callback

Google won't allow an unknown URL. I have registered several URL's but I am getting a new port everytime, so the URL changes on every call. Authorised URL's

On each call I get this error: Authorization error

My problem would be solved if I can get a static port.

Instead of,

final NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();

I need something like this:

final NetHttpTransport httpTransport = 8080;

Code that failed:

final NetHttpTransport httpTransport = new NetHttpTransport();

is still giving a new port everytime.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source