使用Google登录api授权youtube数据api请求 [英] Authorize youtube data api request using google sign in api

查看:727
本文介绍了使用Google登录api授权youtube数据api请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用api中的google来授权youtube数据请求(范围). Google登录可以在我的应用程序中正常运行,并且我已经登录.如何使用Google登录API的结果向YouTube数据API范围发送请求?

我的登录:

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestScopes(new Scope("https://www.googleapis.com/auth/youtube"))
            .build();
    api = new GoogleApiClient.Builder(main.getApplicationContext())
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

这很好.

我从结果中得到一个GoogleSignInAccount和一个GoogleApiClient. 如何向youtube发送请求,例如添加订阅或获取频道名称/ID?

谢谢

草场

解决方案

问Google无法处理/回答我的问题,我现在将自己解决. (有点尴尬的是,像google这样的公司无法帮助正在使用该API的开发人员.)

但这就是我要工作的:

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestScopes(new Scope("https://www.googleapis.com/auth/youtube"))
            .requestIdToken("APIKEY FROM WEBSITE")
            .requestEmail()
            .build();
    api = new GoogleApiClient.Builder(main.getApplicationContext())
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();
    api.connect();

如果您希望android显示登录窗口,则会授权用户:

Intent intent = Auth.GoogleSignInApi.getSignInIntent(api);
            main.startActivityForResult(intent, 9001);

结果可用于以下用途:

Account account = result.getSignInAccount().getAccount();

该帐户现在可以用于在youtube上订阅某人.

GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(
            Main.main,
            Collections.singleton("https://www.googleapis.com/auth/youtube"));
    credential.setSelectedAccount(google.getAccount());
    youTube = new YouTube.Builder(
            new NetHttpTransport(),
            new JacksonFactory(),
            credential)
            .setApplicationName("APPNAME")
            .build();

youtube对象现在可以用于任何您喜欢的东西.

即使我对Google非常失望,也感谢这个社区.

草场

i am trying to authorize a youtube data request (scope) using google sing in api. Google Sign In works perferct inside my app and i am getting logged in. How do I use the result of the google sign in api to send a request to a youtube data api scope?

My Sign In:

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestScopes(new Scope("https://www.googleapis.com/auth/youtube"))
            .build();
    api = new GoogleApiClient.Builder(main.getApplicationContext())
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

This workes fine.

I get a GoogleSignInAccount and a GoogleApiClient from the result. How do I send a request to youtube for example to add a subscription or get the channel name/id?

Thanks

Keba

解决方案

ask Google is not able to work with/answer my question, I will now do it myself. (It´s a little embarrassing that a company like google is not able to help developers who ARE working with there apis.)

But thats what I got to work:

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestScopes(new Scope("https://www.googleapis.com/auth/youtube"))
            .requestIdToken("APIKEY FROM WEBSITE")
            .requestEmail()
            .build();
    api = new GoogleApiClient.Builder(main.getApplicationContext())
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();
    api.connect();

This will authorise the user, if you want android to show a login window:

Intent intent = Auth.GoogleSignInApi.getSignInIntent(api);
            main.startActivityForResult(intent, 9001);

The result can be used as following:

Account account = result.getSignInAccount().getAccount();

The Account can now be used to e.g. subscribe to somebody on youtube.

GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(
            Main.main,
            Collections.singleton("https://www.googleapis.com/auth/youtube"));
    credential.setSelectedAccount(google.getAccount());
    youTube = new YouTube.Builder(
            new NetHttpTransport(),
            new JacksonFactory(),
            credential)
            .setApplicationName("APPNAME")
            .build();

The youtube object can now be used for anything you like.

Thanks for this community, even when i am very disappointed about google.

Keba

这篇关于使用Google登录api授权youtube数据api请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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