Add YouTube Data API to Android Studio

Bigandrewgold picture Bigandrewgold · Aug 11, 2013 · Viewed 33.7k times · Source

So, I am currently messing around with android programming in my free time, and I am using android studio as my ide of choice. I am currently trying to make a very simple app using the youtube api. My issue is that I cant figure out how to actually get the api into my application. I have used file>project structure to add the stuff to my application, but that doesnt work by itself. It stops yelling at me about syntax errors but when it compiles it errors.

I researched this a bit and have found that I need to add stuff to build.gradle or settings.gradle(or both) but i havent found a definitive answer on exactly what to do. Everything I have tried thus far hasnt worked. SO if someone could either explain to me what i have to do, or link me to a place where it explains what to do that would be great

--edit--

I am so confused right now. I started a new project. I added the libs and it was still able to compile. I then added the imports and it threw errors about it. I then added these to the build.gradle and it was able to compile perfectly

compile fileTree(dir: 'libs/youtube', include: '*.jar')
compile fileTree(dir: 'libs/youtube/libs', include: '*.jar')

But when i added this code that requires the library

/** Global instance of the HTTP transport. */
private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();

/** Global instance of the JSON factory. */
private static final JsonFactory JSON_FACTORY = new JacksonFactory();

/** Global instance of Youtube object to make all API requests. */
private static YouTube youtube;

the syntax was fine but it threw an error upon compiling it

 Gradle: Execution failed for task ':Apitest:dexDebug'.
> Failed to run command:

and that was followed by about 100 lines of of file locations

Any ideas as to what i am doing wrong?

Answer

Evgeni Roitburg picture Evgeni Roitburg · Oct 15, 2014

Just add this dependency in gradle file:

compile 'com.google.apis:google-api-services-youtube:v3-rev181-1.22.0'

and use YouTube object.

reference: https://developers.google.com/api-client-library/java/apis/youtube/v3