使用GoogleSignInApi访问YouTube品牌帐户 [英] Access YouTube brand account using GoogleSignInApi
问题描述
我正在遵循此指南: https://developers.google.com/身份/登录/android/
提示我输入我的Google用户,然后我单击确定,就可以访问youtube数据api.
Which prompts me for my Google user and I login ok, I can access the youtube data api.
但是,我希望它提示我选择关联的品牌帐户.这可能吗?我有它从nodejs应用程序工作,但在这种情况下似乎不受支持.
However I want it to prompt me to choose my linked brand account instead. Is this possible? I had it working from a nodejs app but it doesn't seem supported in this case.
推荐答案
原来你不能.暂时不支持.
Turns out you can't. Just not supported at this time.
相反,您需要通过 https://github.com/openid/AppAuth-Android/仅使用youtube范围,即可正确提示您的频道/品牌帐户.
Instead you need to go via https://github.com/openid/AppAuth-Android/ using just the youtube scope, this prompts for your channels/brand accounts correctly.
然后将结果与youtube api一起使用,这是我在AppAuth TokenActivity中完成的:
Then to use the result with the youtube api I did this in the AppAuth TokenActivity:
/**
* 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);
});
这篇关于使用GoogleSignInApi访问YouTube品牌帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!