NoLinkedYoutubeAccount error 401 when uploading videos on Youtube with java

google-api-java-client, java, youtube-api

Solution

As the error say, you have not linked the account credential to youtube.

You can solve that problem: - Connecting with the account used on the app in www.youtube.com - Trying to upload a video - Setting name and surname when youtube ask, and process to link to gmail.

Done!!! I tried before using my app to upload the video using Firefox.

Problem

i would like to upload videos on youtube from my java web application: I want to receive (server side) my authToken and form-action so to upload a video. - I've created a new google/youtube account - I've created a youtube channel in my account - i've created a new project in my google console api as a Service Account Now i'm trying to implement my code with oAuth 2.0. I've got the accessToken but, when i try to call the service getFormUploadToken(url, object) the response is always the same "NoLinkedYoutubeAccount error 401". i've also verified the account by the google support page http://www.youtube.com/my_account_unlink but it's seems ok. Does anybody have an idea about this problem? This is my code: ``` HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); JsonFactory JSON_FACTORY = new JacksonFactory(); String accessToken = ""; GoogleCredential credential = null; credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT) .setJsonFactory(JSON_FACTORY) .setServiceAccountId(CLIENT_EMAIL) .setServiceAccountScopes("http://gdata.youtube.com") .setServiceAccountPrivateKeyFromP12File(new File(PRIVATE_KEY_PATH)) .build(); credential.refreshToken(); accessToken = credential.getAccessToken(); YouTubeService service = new YouTubeService(CLIENT_ID, DEV_KEY); service.setAuthSubToken(accessToken, null); VideoEntry newEntry = new YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup(); mg.setTitle(new MediaTitle()); mg.getTitle().setPlainTextContent("My Test Movie"); URL uploadUrl = new URL("http://gdata.youtube.com/action/GetUploadToken"); FormUploadToken token = service.getFormUploadToken(uploadUrl, newEntry); ``` Thanks a lot, Albert III

Original source