1

I am creating an android app, using the youtube API where you play and then favorite YouTubeVideos.I have (I think correctly) gotten the Auth Token using Account Manager and oauth2 for the user.

What I am wondering, is where to go next? I would like to create an instance of a YouTube, so that I can favorite the videos. After looking at the constructor, I do not know how to incorporate the access token into it. I have my Client_ID and Client_Secret, but all the examples I have seen have just needed that. How will the YouTube instance know who's account it is if it never takes in the Auth Token?

This is the constructor:

YouTube(HttpTransport transport, JsonFactory jsonFactory, HttpRequestInitializer httpRequestInitializer)

This is the time I made an instance of a YouTube but did not need account manager because I was only searching YouTube, not accessing any private information:

youtube = new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY, new HttpRequestInitializer() {
            public void initialize(HttpRequest request) throws IOException {}
          }).setApplicationName("youtube-isabelle-search-sample").build();


        YouTube.Search.List search = youtube.search().list("id,snippet");

Any guidance would be great! Thanks a lot!

Isabelle
  • 13
  • 1
  • 3

1 Answers1

3

You need to create a GoogleCredential and set this credential into this YouTube object.

For Android apps, you can use GoogleAccountCredential to get the OAuth2 token. It stores the token inside the credential.

YouTube Direct Lite Android example has a good example of using it.

Ibrahim Ulukaya
  • 12,767
  • 1
  • 33
  • 36
  • Thanks, that does help. But with the googleAccountCredential, there's nowhere for me to put the client_id and client_secret. Or do I not need that to favorite youtube videos? Should I just use a GoogleCredential? – Isabelle Jul 12 '13 at 16:17
  • It uses simple API access. As long as you set simple API access with your SHA1 key as an Android app in your dev console, you'll be fine. – Ibrahim Ulukaya Jul 12 '13 at 16:35
  • I am getting this error: "07-18 11:39:48.089: W/System.err(21248): Caused by: com.google.android.gms.auth.UserRecoverableAuthException: NeedPermission" Do you know what this error is from? I followed the other website example (thanks for that!) – Isabelle Jul 18 '13 at 16:42
  • Mens you didn't set the simple api access for android from your api dev console, or not enabled youtube data api from api access tab – Ibrahim Ulukaya Jul 19 '13 at 03:08
  • Hi, what if i've acquired the token with the Google Play services library? (https://developers.google.com/android/guides/http-auth) in this case i have only a String.. how am i supposed to use it? – Pierfrancesco Soffritti Jun 21 '15 at 20:16
  • i've tried using the GoogleAccountCredential class, @Isabelle, have you solved your issue about "There was an IO error: com.google.android.gms.auth.UserRecoverableAuthException: NeedPermission : null" ? i'm receiving the same error, but i've enabled the api and the android access on the dev console – Pierfrancesco Soffritti Jun 21 '15 at 22:19