如何在YouTube上播放私人视频?

时间:2015-01-23 07:46:50

标签: android video youtube oauth-2.0 youtube-api

我正在开发一个应用程序,可以播放当前登录用户的所有视频。我可以播放所有公共视频,如播放列表视频,观看以后的视频等,但我无法播放我的私密访问上传视频。我使用 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();

我正在使用此代码获取accessstoken。

 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来播放私人视频吗? 的问候,

1 个答案:

答案 0 :(得分:1)

检索流媒体网址没有正确的文档(从当前登录的人员帐户中检索视频网址)。经过多次努力,这就是解决方案。

1)需要额外的范围:" http://gdata.youtube.com" :访问类型:"离线"

2)需要以下标题

*。 Content-Type:application / atom + xml

*。授权:持票人  (根据文档,这是" GoogleLogin auth =")

*。 GData-Version:2

*。 X-Youtube-Deviceauthtoken:devkey

相关问题