Pregunta

I've been having tremendous problems with connecting my android app to the youtube API. Firstly I tried to go along the route of using the native youtube gdata java client(http://code.google.com/p/gdata-java-client/). I had read that this could then be integrated into an android app easily enough and so I set about doing that but I would stumble every time at the line

    YouTubeService ytservice = new YouTubeService("AppName",Dev_Key);   

I'd enter the correct details here, even have all the necessary external jars but every time I would be given a NoClassDefFoundError reporting that YouTubeService could not be found and neither could it's superclass, MediaService. (Just so you know, I had gdata-youtube-2.0.jar, gdata-client-1.0.jar, gdata-media-1.0.jar, guava.11.0.2.jar and jsr305.jar)

So then I tried which appeared to support android (http://code.google.com/p/google-api-java-client/wiki/Android). There was even a sample example where google tasks had been integrated so it looked promising. It didn't have an actual YouTube class like it did have a taskService but it did support OAuth 2.0 login which I could work with by just sending off URL requests to the youtube API with OAuth 2.0 authentication. I tried this but when the only key I could get from it in combination with android's AccountManager was an auth key token. Posting this with the URL request to google resulted in an 'authentication required' response from youtube(because i was providing an incorrect access token, it was at least twice the size of a working access token i was comparing it with).

How can I find the access token that I need for the youtube API from the AccountManager? Or even better, how can I get the YouTubeservice to work? Thanks

rory

Edit

Amad, thanks for the answer but unfortunately that is what i am already doing:
(source: themobilelook.com)

maybe it'll help if i supply my project folder: here it's a barebones setup, literally just to test if the YouTubeService works.

using adt 20, jdk compliance level 1.6

if you manage to create a working version then itnwoild be great if you could share it

¿Fue útil?

Solución

The YouTube API library/libraries must be included in the project. By going to the Project Properties > Build Path > Order and Export tab, you can tick the checkbox next to the all YouTube-API-related libraries to ensure that they will be included in the project when you export it. Make sure to clean and rebuild after doing this.

As for the access token... not totally sure. The documentation may help there. This Google Groups thread may help also.

Otros consejos

If you get NoClassDefFoundError during Runtime, then I suspect you did not include them to work at runtime. You have to check the checkbox for each .jar like this:

enter image description here

(Of course you have to add them to your java build path first)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top