Upload to Youtube

All your problems with Audio, Video and Images.

Upload to Youtube

Postby Kryex » Tue Oct 04, 2011 12:07 am

Hi everyone.

I am developing an app that uploads a video in the sdcard to youtube and returns the youtube video url after. However, I have not been able to successfully do so.

I have tried with ACTION_SEND:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onUploadClick(View v) {
  2.  Intent uploadIntent = new Intent(Intent.ACTION_SEND);
  3.  // In a real app, video would be captured from camera.
  4.  File f = new File("/sdcard/test.mov");
  5.  uploadIntent.setDataAndType(Uri.fromFile(f), "video/quicktime");
  6.  startActivity(Intent.createChooser(uploadIntent, "Upload"));
  7. }
Parsed in 0.011 seconds, using GeSHi

But, oddly, with this implementation I do not have Youtube as an option for the upload. I have Bluetooth, Mail, Dropbox, Facebook, Flickr, Gmail and Handcent. But not Youtube. Any thoughts on this?
Besides, is it possible using this method to have the url of the youtube video after uploaded? How?

I have also tried using Youtube API for Java, and again no success. I added all the libraries needed (gdata-client-1.0.jar, gdata-media-1.0.jar and gdata-youtube-2.0,jar). However, when I run it I get a NoClassDefFoundError for com.google.gdata.client.youtube.YouTubeService, despite having the right libs and imports.
Here is the code I am using:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. YouTubeService service = new YouTubeService(clientID, developer_key);
  2. VideoEntry newEntry = new VideoEntry();
  4. YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
  5. mg.setTitle(new MediaTitle());
  6. mg.getTitle().setPlainTextContent("My Test Movie");
  7. mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "Autos"));
  8. mg.setKeywords(new MediaKeywords());
  9. mg.getKeywords().addKeyword("cars");
  10. mg.getKeywords().addKeyword("funny");
  11. mg.setDescription(new MediaDescription());
  12. mg.getDescription().setPlainTextContent("My description");
  13. mg.setPrivate(false);
  14. mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "mydevtag"));
  15. mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "anotherdevtag"));
  17. newEntry.setGeoCoordinates(new GeoRssWhere(37.0,-122.0));
  18. // alternatively, one could specify just a descriptive string
  19. // newEntry.setLocation("Mountain View, CA");
  21. MediaFileSource ms = new MediaFileSource(new File("file.mov"), "video/quicktime");
  22. newEntry.setMediaSource(ms);
  24. String uploadUrl =
  25.   "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";
  27. VideoEntry createdEntry = service.insert(new URL(uploadUrl), newEntry);
Parsed in 0.013 seconds, using GeSHi

To sum up, my questions are:
- What am I doing wrong in both approaches?
- Regarding my simple objective of uploading a video to youtube and getting its youtube link after, which method do you recommend? Even if it's neither of those above.

Thank you.
Posts: 6
Joined: Thu Dec 03, 2009 8:09 pm


Re: Upload to Youtube

Postby Kryex » Tue Oct 04, 2011 10:07 pm

---- Update 04/10 ----

- After trying with a differente phone I found out that Youtube not showing up as choice to upload the video is my phone's problem (probably due to the ROM).
However, even if it does work using intents is not the way to go because I cannot get the URL back and that is essential.
- After some research it seems that the second method is not possible. The Youtube API for Java does not work in Android.

That being said, I am looking for suggestions on how to upload a video to Youtube in Android.
What I really want is to choose a video file, upload it to Youtube and get the youtube URL. Preferably without any interference from the user, who only chooses the file and then the uploading and URL retrieving runs "in the background".
Any suggestions? What is the easiest and fastest way to achieve this?

Posts: 6
Joined: Thu Dec 03, 2009 8:09 pm


Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 8 guests