问题
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!
回答1:
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.
来源:https://stackoverflow.com/questions/17604593/what-to-do-after-getting-auth-token-android-youtube-api