1

I will keep it simple. my requirement is to authenticate a static Google account (with a username and the password) with OAuth2 in my android application. and then after getting the oauth token i will upload some videos to YouTube. all the other work is done of uploading. but currently i am using GoogleAuthUtil to pick an account from android System. like given here (http://developer.android.com/google/auth/http-auth.html)

Now I want to disable this functionality. I just want that all videos will be uploaded to a fixed youtube/Google account. I also went through this question but there is no answer also.

I also found this question and it was very helpful but the tutorial it is using depricated GoogleClientLogin and it is throwing an exception 403 forbidden when i try to use GoogleClientLogin. Then I tried the same using OAuth2 url it always asks to sign in to first time. so is there anyway to authenticate the google account without any user involvment and get the the OAuth token. please help me.

Thanks

Community
  • 1
  • 1
Abdul Mohsin
  • 1,253
  • 1
  • 13
  • 24

2 Answers2

1

See How do I authorise an app (web or installed) without user intervention? (canonical ?)

That answer talks about a server application, but an Android application behaves in just the same way. So you would embed the refresh token in your app, or have it downloaded and stored, and then use that to generate an access token whenever your app needs to access YouTube.

Community
  • 1
  • 1
pinoyyid
  • 21,499
  • 14
  • 64
  • 115
  • it didn't helped :(. oauth 2 playground is an app that this is using to authenticate. please read my requirement. i just want something that can authenticate google id and password and give me the oauth token – Abdul Mohsin Nov 13 '14 at 12:52
  • This is the correct answer - I know because I've done it. If you think it isn't, then you need to try harder to understand OAuth. Especially note step 7 where you supply the credentials of your own app. – pinoyyid Nov 13 '14 at 14:25
  • ok. thanks i will try it harder. already i spent 2 days on it :( – Abdul Mohsin Nov 13 '14 at 14:37
1

Finally I found the solution to my problem. Now I am able to upload videos to a static YouTube account from my android app. although Youtube Data api v2 is deprecated but I used this for my requirement. The following code I am using to upload videos to YouTube

    YouTubeService service = new YouTubeService("project id on console.developer.google.com","androidkey");
    service.setUserCredentials("yourYouTubeAccount@gmail.com", "yourPassword");
    VideoEntry newEntry = new VideoEntry();
    YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
    mg.setTitle(new MediaTitle());
    mg.getTitle().setPlainTextContent("Video Title");
    mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "Tech"));
    mg.setKeywords(new MediaKeywords());
    mg.getKeywords().addKeyword("anyKeyword");
    mg.setDescription(new MediaDescription());
    mg.getDescription().setPlainTextContent("VIDEO DESCRIPTION");
    mg.setPrivate(false);
    mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "mydevtag"));
    mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "anotherdevtag"));
    MediaFileSource ms = new MediaFileSource(videoFileToUpload, "video/quicktime");
    newEntry.setMediaSource(ms);
    VideoEntry createdEntry = service.insert(new URL(Constant.YOUTUBE_UPLOAD_URL), newEntry);
    Log.v("TAG", "VIDEO INSERTED ID : " + createdEntry.getId());

You will require the following Libraries to use the code:

  • activation.jar
  • additionnal.jar
  • gdata-base-1.0.jar
  • gdata-core-1.0.jar
  • gdata-media-1.0.jar
  • gdata-youtube-2.0.jar
  • gdata-youtube-meta-2.0.jar
  • guava-11.0.2.jar
  • mail.jar
  • servlet-api.jar

for gdata libraries please go to this link and download both gdata-src.java-x.xx.x.zip and gdata-samples.java-x.x.x.zip. Extract these folders and you will get the required jars

-Thanks

Abdul Mohsin
  • 1,253
  • 1
  • 13
  • 24
  • I have downloaded `gdata-youtube-2.0.jar`, but I am still unable to use **setUserCredentials** method of the class `YouTubeService`. Am I doing anything wrong or missing something? The package, I have imported is _com.google.gdata.client.youtube.YouTubeService_ – Narendra Singh Oct 05 '16 at 15:22
  • The above issue fixed by using - `compile group: 'com.google.gdata', name: 'core', version: '1.47.1'` dependency – Narendra Singh Oct 06 '16 at 07:57
  • btw, what should be the value for `Constant.YOUTUBE_UPLOAD_URL`? – Narendra Singh Oct 06 '16 at 08:01
  • I have the same question as @NarendraJi. Did you manage to find it out? What is the value of Constant.YOUTUBE_UPLOAD_URL? Is Constant supposed to be Constants? – Sachin Rammoorthy Apr 20 '19 at 22:00