YouTube GData API and Android

If you want to use the YouTube API v2 to search for content on YouTube with an Android device, the recommended way is the use the gdata-http-client java package. However, this requires that you parse the XML returned yourself, and navigate it. The reason is that out of the box the YouTube API v2 java library doesn’t work on Android. This is due to a requirement on the javax.mail package which isn’t available officially on Android.

However, thanks to the wonders of the internet, you can get a package of javax.mail and activation which have been compiled to work on Android. The javamail-android project contains jars have been compiled to work with Android and it’s DEXer.

For those using Maven, I have added these to my maven repo. Add the following repository to your pom to make it available:

<repository>
  <id>serenity-thirdparty-repo</id>
  <url>http://kingargyle.github.com/repo</url>
  <layout>default</layout>
   <releases>
      <enabled>true</enabled>
      <updatePolicy>always</updatePolicy>
      <checksumPolicy>warn</checksumPolicy>
   </releases>
</repository>

Then for dependencies for the YouTubeAPI you can add the following to your pom for your app.

<dependency>
         <groupId>com.google.gdata</groupId>
         <artifactId>gdata-youtube</artifactId>
         <version>2.0</version>
      </dependency>
      <dependency>
         <groupId>com.google.gdata</groupId>
         <artifactId>gdata-youtube-meta</artifactId>
         <version>2.0</version>
      </dependency>
      <dependency>
         <groupId>com.google.gdata</groupId>
         <artifactId>gdata-core</artifactId>
         <version>1.0</version>
      </dependency>
      <dependency>
         <groupId>com.google.gdata</groupId>
         <artifactId>gdata-media</artifactId>
         <version>1.0</version>
      </dependency>
      <dependency>
         <groupId>com.google.gdata</groupId>
         <artifactId>gdata-client</artifactId>
         <version>1.0</version>
      </dependency>
      <dependency>
         <groupId>com.google.gdata</groupId>
         <artifactId>gdata-client-meta</artifactId>
         <version>1.0</version>
      </dependency>
      <dependency>
         <groupId>com.google.guava</groupId>
         <artifactId>guava</artifactId>
         <version>11.0.2</version>
      </dependency>
      <dependency>
        <groupId>com.google.gdata</groupId>
        <artifactId>mail</artifactId>
        <version>1.0</version>
      </dependency>      
      <dependency>
        <groupId>com.google.gdata</groupId>
        <artifactId>activation</artifactId>
        <version>1.0</version>
      </dependency>

You may want to run ProGuard to help cut down the size of the guava library brought in by the app, as it alone adds about 1.1mb to the size of your application.

With the above added you can use the YouTube GData v2 API to search YouTube for videos and deal with java objects.
 

Reference: YouTube GData API and Android from our JCG partner David Carver at the Intellectual Cramps blog.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

Leave a Reply


× seven = 35



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close