获取身份验证令牌后该怎么办-Android Youtube API [英] What to do after getting Auth Token - Android Youtube API

查看:111
本文介绍了获取身份验证令牌后该怎么办-Android Youtube API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用播放的youtube API创建一个android应用,然后使用喜欢的YouTubeVideos.我(我认为正确)已经使用帐户管理器和oauth2为用户获取了Auth令牌.

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.

我想知道的是,下一步要去哪里?我想创建一个YouTube实例,以便可以收藏这些视频.看完构造函数后,我不知道如何将访问令牌合并到其中.我有我的Client_ID和Client_Secret,但是我所看到的所有示例都需要它.如果YouTube实例从不使用身份验证令牌,怎么会知道它是谁的帐户?

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?

这是构造函数:

YouTube(HttpTransport transport, JsonFactory jsonFactory, HttpRequestInitializer httpRequestInitializer)

这是我创建YouTube实例但不需要客户经理的时候,因为我只是搜索YouTube,不访问任何私人信息:

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!

推荐答案

您需要创建GoogleCredential并将此凭据设置到该YouTube对象中.

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

对于Android应用,您可以使用

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

YouTube Direct Lite Android示例提供了一个很好的示例.

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

这篇关于获取身份验证令牌后该怎么办-Android Youtube API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆