使用谷歌玩服务与YouTube [英] Using Google play services with youtube

查看:659
本文介绍了使用谷歌玩服务与YouTube的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用新的YouTube API V3: https://developers.google.com/ YouTube的/ V3 /
在我的Andr​​oid应用程序。

I am trying to use the new Youtube API V3 : https://developers.google.com/youtube/v3/ in my android app.

要登录用户在YouTube等服务,我选择了新的谷歌游戏服务: http://developer.android.com/google/play-services/index.html

To login the user to youtube services, I chose the new Google Play Services : http://developer.android.com/google/play-services/index.html

下面是我的code:

AccountManager manageurcomptes = AccountManager.get(ActiviteGeneral.this);
Account[] comptes = manageurcomptes
                        .getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
String jeton;
try {
    jeton = GoogleAuthUtil.getToken(ActiviteGeneral.this, comptes[0].name,
        "audience:server:client_id:xxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com");
    int i = 0;
} catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
} catch (GoogleAuthException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();

对于GoogleAuthUtil.getToken范围的参数,我也跟着从Android的Developper博客的文章:验证后端从Android应用程序调用的http://android-developers.blogspot.fr/2013/01/verifying-back-end-calls-from-android.html和注册我的谷歌API的控制台应用程序。

For the GoogleAuthUtil.getToken scope parameter, I followed the article from Android Developper Blog : "Verifying Back-End Calls from Android Apps" http://android-developers.blogspot.fr/2013/01/verifying-back-end-calls-from-android.html and registered my app on Google API Console.

我创建了一个客户端ID为安装的应用程序。

I created a "Client ID for installed applications".

其结果是detailMessage=未知一个GoogleAuthException。

The result is a GoogleAuthException with "detailMessage" = "Unknown".

在哪儿错了吗?

推荐答案

我做了演示了如何从一个Android应用程序,工作得非常好访问YouTube API v3的一个例子:

I made an example that shows how can access to the YouTube API v3 from an Android app that works very well:

http://lookthis$c$c.blogspot.com.ar/2013/01/utilizando-youtube-data-api-v3-desde.html

其实这个例子是基于在展示了如何使用任务API从Android应用程序的官方例子。我修改使用YouTube API认证范围的例子。

Actually this example is based in the official example that shows how to use the task API from an Android app. I modified the example to use the YouTube API authentication scope.

这篇文章是在西班牙,但你可以使用在文章末尾的​​链接下载该项目的源代码code。

The article is in spanish but you can download the source code of the project using the link at the end of the article.

解决你的问题,主要件code是以下内容:

The main piece of code to solve your problem is the following:

// Google Accounts
credential = GoogleAccountCredential.usingOAuth2(this, YouTubeScopes.YOUTUBE, YouTubeScopes.YOUTUBE_READONLY);
SharedPreferences settings = getPreferences(Context.MODE_PRIVATE);
credential.setSelectedAccountName(settings.getString(PREF_ACCOUNT_NAME, null));
// YouTube client
service =
        new com.google.api.services.youtube.YouTube.Builder(transport, jsonFactory, credential)
            .setApplicationName("Google-YouTubeAndroidSample/1.0").build();

这篇关于使用谷歌玩服务与YouTube的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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