【问题标题】:Youtube api channel selectorYoutube api 频道选择器
【发布时间】:2014-12-18 09:24:57
【问题描述】:

现在您可以创建多个 Youtube 频道。在我的 Android 应用中,我需要让用户选择其中一个频道并使用它(获取订阅视频等)。

我想模拟官方的 Youtube 应用程序,您可以在其中选择我在 Youtube 帐户中创建的频道之一。

编辑:

最后我用易卜拉欣的建议解决了这个问题。在 web 视图中,我使用了 oAuth2 身份验证,如下所示:

https://accounts.google.com/o/oauth2/auth?client_id=CLIENT_ID&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/youtube&response_type=code&access_type=offline

然后接收token来获取access_token:

String url = "https://accounts.google.com/o/oauth2/token";

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(5);

nameValuePairs.add(new BasicNameValuePair("grant_type", "authorization_code"));
nameValuePairs.add(new BasicNameValuePair("client_id", YoutubeBase.CLIENT_ID_NUMBER));
nameValuePairs.add(new BasicNameValuePair("client_secret", YoutubeBase.CLIENT_SECRET));
nameValuePairs.add(new BasicNameValuePair("code", code));
nameValuePairs.add(new BasicNameValuePair("redirect_uri", YoutubeBase.REDIRECT_URI));
response = RestClient.postGoogleData(url, nameValuePairs);

最后使用 access_token 调用 Youtube Data API:

https://gdata.youtube.com/feeds/api/users/default?v2.1&access_token=" + accesToken

我使用过 API v2,但适用于 v3。

【问题讨论】:

    标签: youtube-api android-youtube-api youtube-channels


    【解决方案1】:

    当前的 Android 原生 OAuth2 客户端没有内置页面选择器。在构建完成之前,唯一的解决方法是执行 Web 版本 Oauth2,获取令牌,然后在您的请求中使用该令牌。

    【讨论】:

    • 感谢易卜拉欣的回复。我需要一个频道选择器,因为对gdata.youtube.com/feeds/api/users/default?v2.1 的调用会返回创建的第一个频道,而不是默认频道。您知道是否可以从一个拥有多个频道的帐户获取默认的 youtube 频道?提前谢谢!!!!
    • 感谢易卜拉欣。我用你的建议解决了这个问题。我已经编辑了我的问题。再次感谢!
    猜你喜欢
    • 2022-11-07
    • 2023-03-10
    • 2014-10-02
    • 2020-12-19
    • 2014-05-02
    • 2015-01-25
    • 2016-02-15
    • 2018-10-19
    • 1970-01-01
    相关资源
    最近更新 更多