【发布时间】:2015-03-22 05:11:57
【问题描述】:
我正在开发一个可以播放当前登录用户的所有视频的应用程序。我可以播放所有公共视频,如播放列表视频、观看以后的视频等,但我无法通过私人访问播放我上传的视频。我正在使用 WebView 登录 Google 帐户,但我没有使用 AccountManager 因为如果我使用 AccountManager 它将触发本机 Android 流程,我不希望这样。 我正在使用以下代码获取 authURL 。
String authUrl = new GoogleAuthorizationCodeRequestUrl(CLIENT_ID, REDIRECT_URI, Arrays.asList("https://gdata.youtube.com",YouTubeScopes.YOUTUBE,YouTubeScopes.YOUTUBE_READONLY, YOUTUBE_EMAIL_SCOPE, Scopes.PROFILE, YouTubeScopes.YOUTUBE)).build();
我正在使用此代码获取访问令牌。
final GoogleAuthorizationCodeFlow flow = YoutubeGoogleAuthorizationCodeFlow.getInstance(getApplicationContext());
GoogleAuthorizationCodeTokenRequest tokenRequest =
flow.newTokenRequest(authorizationCode).setRedirectUri(YouTubeModule.REDIRECT_URI);
GoogleTokenResponse tokenResponse = tokenRequest.execute();
credential = flow.createAndStoreCredential(tokenResponse, "");
token = credential.getAccessToken();
并使用此链接中的代码播放公共视频。 play streaming in VideoView, convert url to rtsp
如果我像这样更改代码
String gdy = "http://gdata.youtube.com/feeds/api/videos/";
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
youtubeVidId = extractYoutubeId(videoId);
URL url = new URL(gdy + youtubeVidId);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Authorization", String.format("GoogleLogin auth=\"%s\"", authToken));
connection.setRequestProperty("GData-Version", "2");
connection.setRequestProperty("X-Youtube-Deviceauthtoken", devKey);
我应该可以播放视频,但不知何故 authToken 不正确。
所以这是我的问题,您需要不同的 authToken 来播放私人视频吗? 问候,
【问题讨论】:
标签: android video youtube oauth-2.0 youtube-api