Reputation: 1435
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
Upvotes: 1
Views: 1045
Reputation: 1435
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("[email protected]", "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:
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
Upvotes: 1
Reputation: 22286
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.
Upvotes: 1