首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用YouTube访问GoogleSignInApi品牌帐户

使用YouTube访问GoogleSignInApi品牌帐户
EN

Stack Overflow用户
提问于 2017-05-18 06:30:33
回答 1查看 977关注 0票数 1

我正在遵循以下指南:https://developers.google.com/identity/sign-in/android/

这提示我输入我的谷歌用户,我登录ok,我可以访问youtube数据api。

然而,我想要它提示我选择我的链接品牌帐户而不是。这个是可能的吗?我让它在nodejs应用程序中工作,但在本例中它似乎不受支持。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-22 03:51:44

结果你做不到。只是现在不支持。

相反,您需要使用youtube范围通过https://github.com/openid/AppAuth-Android/,这提示您的频道/品牌帐户正确。

然后,为了使用youtube api的结果,我在AppAuth TokenActivity中这样做了:

代码语言:javascript
复制
/**
 * Define a global instance of the HTTP transport.
 */
public static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();

/**
 * Define a global instance of the JSON factory.
 */
public static final JsonFactory JSON_FACTORY = new JacksonFactory();

private YouTube mYoutube;

@MainThread
private void fetchUserInfo(String accessToken, String idToken, AuthorizationException ex) {
    if (ex != null) {
        Log.e(TAG, "Token refresh failed when fetching user info");
        mUserInfoJson.set(null);
        runOnUiThread(this::displayAuthorized);
        return;
    }

    mYoutube = new YouTube.Builder(TokenActivity.HTTP_TRANSPORT, TokenActivity.JSON_FACTORY, new HttpRequestInitializer() {
            @Override
            public void initialize(HttpRequest httpRequest) throws IOException {
                httpRequest.getHeaders().setAuthorization("Bearer " + accessToken);
            }
        })
        .build();

    mExecutor.submit(() -> {
        try {
            YouTube.LiveBroadcasts.List list = mYoutube.liveBroadcasts()
                    .list("id, snippet, contentDetails, status")
                    .setMine(true);
            Log.i(TAG, "List to string " + list.toString());
            LiveBroadcastListResponse response = list
                    .execute();
            JSONObject obj = new JSONObject();
            obj.put("name", response.getItems().get(0).getSnippet().getTitle());
            mUserInfoJson.set(obj);
        } catch (IOException e) {
            Log.e(TAG, "Failed to construct user info endpoint URL", e);
        } catch (JSONException e) {
            Log.e(TAG, "Failed to set name", e);
//            e.printStackTrace();
        }
        runOnUiThread(this::displayAuthorized);
    });
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44040198

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档