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.
Related Whitepaper:

Rapid Android Development: Build Rich, Sensor-Based Applications with Processing

Create mobile apps for Android phones and tablets faster and more easily than you ever imagined

Use 'Processing', the free, award-winning, graphics-savvy language and development environment, to work with the touchscreens, hardware sensors, cameras, network transceivers, and other devices and software in the latest Android phones and tablets.

Get it Now!  

Leave a Reply


× 9 = twenty seven



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
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.

Sign up for our Newsletter

20,709 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books