1

In my application, the user can upload a video directly to my youtube channel to make it public.

enter image description here

  • The client part of my application acquires the video and uploads it to my server.
  • My server then uses Youtube API to upload the video to my youtube channel.

And here is how I implemented it:

  1. Created a new project: https://console.developers.google.com/project

  2. Enabled YouTube Data API v3: enter image description here

  3. Created a Key for server applications: enter image description here

  4. Here's my java code:

    YouTube youtube = new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY, new HttpRequestInitializer() {
        @Override
        public void initialize(HttpRequest httpRequest) throws IOException {
    
        }
    })//
    .setYouTubeRequestInitializer(new YouTubeRequestInitializer("XXXX"))//same as above
    .setApplicationName("Some Name")//is it important?
    .build();
    

The rest of the java code is the same as the code samples

But I can't get this to work, and I'm getting:

GoogleJsonResponseException code:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized

Any idea why? What Can I check?

Is the API KEY sufficient here ?

Thank you

Majid Laissi
  • 19,188
  • 19
  • 68
  • 105

1 Answers1

1

You need a full OAuth for this, also use as installed application rather server application. And user has to go through OAuth2. Service accounts are not supported in Data API v3.

More info:https://developers.google.com/youtube/v3/guides/authentication

You can check Java samples here: https://github.com/youtube/api-samples/tree/master/java

Ibrahim Ulukaya
  • 12,767
  • 1
  • 33
  • 36
  • well my users are not required to have youtube accounts, so they cannot go through OAuth2 as it's my youtube account not theirs. – Majid Laissi Aug 25 '14 at 20:08
  • 1
    then you'll once go through OAuth2 and then you'll be done. Or get your token from playground and use that token for the YouTube API. https://developers.google.com/oauthplayground/ – Ibrahim Ulukaya Aug 26 '14 at 19:42