Android Core

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.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Back to top button