我正在遵循以下指南:https://developers.google.com/identity/sign-in/android/
这提示我输入我的谷歌用户,我登录ok,我可以访问youtube数据api。
然而,我想要它提示我选择我的链接品牌帐户而不是。这个是可能的吗?我让它在nodejs应用程序中工作,但在本例中它似乎不受支持。
发布于 2017-05-22 03:51:44
结果你做不到。只是现在不支持。
相反,您需要使用youtube范围通过https://github.com/openid/AppAuth-Android/,这提示您的频道/品牌帐户正确。
然后,为了使用youtube api的结果,我在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);
});https://stackoverflow.com/questions/44040198
复制相似问题