Sunil Sunny
Sunil Sunny

Reputation: 3994

How to play private videos in YouTube?

I am developing an app that can play all the videos of the currently logged in user.I can play all the public videos like playlist videos,watch later videos etc but I am no able to play My upload videos with private access.I am using a WebView for logging in Google account and I am not using AccountManager because if I use the AccountManager it will trigger the native Android flow and I don't want that. I am using the following code for getting 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();

I am using this code for getting the accesstoken.

 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();

And used code from this link to play public videos. play streaming in VideoView, convert url to rtsp

if I am changing the code like this

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);

I should be able to play videos but somehow the authToken for that is not correct.

So this is my question you need a different authToken for playing private videos ? Regards,

Upvotes: 0

Views: 2128

Answers (1)

Sunil Sunny
Sunil Sunny

Reputation: 3994

Retrieving streaming URLS doesn't have a proper documentation (Retrieving video urls from the currently logged in persons account). After lot of struggle this is the solution for this.

1) Needed additional scope : "http://gdata.youtube.com" :Access type : "Offline"

2)needed the following headers

*. Content-Type : application/atom+xml

*. Authorization : Bearer (As per documentation this is "GoogleLogin auth =")

*. GData-Version : 2

*. X-Youtube-Deviceauthtoken : devkey

Upvotes: 1

Related Questions