Answer the question
In order to leave comments, you need to log in
Why does Google login error occur?
I am writing a Java application that should upload videos to YouTube (one of its functions). I decided to do authorization not through the API, but by emulating a browser. Please do not write something in the spirit of "you need to break your fingers for this", "why is this necessary", and so on. There were reasons for that, and not only sports interest :)
I chose Apache Commons HTTP Client as the client. As a result, I fully reproduced the authorization on YouTube (although for some reason it doesn’t allow it again for the same cookies, which is very strange, every time you start the application you have to repeat the process from scratch), I debugged the video upload, I upload the file in segments, in response I get the correct statuses, and at the very end I get the FINALIZED status. It would seem that it's time to celebrate, but... I can't "commit" this video. It doesn't appear anywhere - I don't see it either in the browser or in the video manager loaded by my own program through the same HTTP Client with the same cookies right after the file download is complete.
Then I thought that it would be necessary to reproduce all sorts of auxiliary requests that the browser sends during download. After digging, I found two requests to the www.googleapis.com server, both without cookies. At the same time, the Firefox debugger for some reason did not see a useful payload in them (in JSON format, the request method is POST).
Chrome saw this data. Implemented them. The first one does not return anything of value, but the second one is important - it returns the ID of the video in the YouTube system (which is then needed, in particular, for another important AJAX request). And this second request is failing me. JSON is valid, I substitute all the data correctly, but in response I get the following error:
{
"items": [
{
"id": {
"frontendKey": "web_upload:b6f80105-8d27-4d57-b3a0-bebd857de319:0"
},
"feedback": {
"videoId": {
"registrationStatus": "STATUS_FAILED",
"failureReason": "FAILED_ACCOUNT_ERROR"
}
}
}
]
}
private void unlockStatusAPI() {
try {
HttpPost httpPost = new HttpPost("https://www.googleapis.com/videofeedback/v1/feedback/list");
httpPost.setHeader(new BasicHeader("Origin", "https://www.youtube.com"));
httpPost.setHeader(new BasicHeader("Content-Type", "application/json"));
httpPost.setHeader(new BasicHeader("Accept-Encoding", "gzip, deflate"));
httpPost.setEntity(org.apache.http.client.entity.EntityBuilder.create().setText("{\"client\":{\"name\":\"youtube_web_uploads\",\"version\":\"" + web_upload_token.split(":")[1] + "\",\"token\":\"" + web_upload_token.split(":")[2] + "\"},\"queries\":[{\"id\":{\"frontendKey\":\"web_upload:" + web_upload + ":0\"},\"choice\":{\"editorSuggestions\":true}}]}").build());
CloseableHttpResponse response = hc.execute(httpPost);
response.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
private void unlockStatusAPI2() {
try {
HttpPost httpPost = new HttpPost("https://www.googleapis.com/videofeedback/v1/feedback/list");
httpPost.setHeader(new BasicHeader("Origin", "https://www.youtube.com"));
httpPost.setHeader(new BasicHeader("Content-Type", "application/json"));
httpPost.setHeader(new BasicHeader("Accept-Encoding", "gzip, deflate"));
httpPost.setEntity(org.apache.http.client.entity.EntityBuilder.create().setText("{\"client\":{\"name\":\"youtube_web_uploads\",\"version\":\"" + web_upload_token.split(":")[1] + "\",\"token\":\"" + web_upload_token.split(":")[2] + "\"},\"queries\":[{\"id\":{\"frontendKey\":\"web_upload:" + web_upload + ":0\"},\"choice\":{\"editorSuggestions\":true,\"videoId\":true,\"videoInfo2\":true,\"videoIssues\":true,\"processingProgress\":true,\"youtubeStatus\":true,\"thumbnailsDone\":true}}]}").build());
CloseableHttpResponse response = hc.execute(httpPost);
HttpEntity entity = response.getEntity();
String line = "";
br = new BufferedReader(new InputStreamReader(entity.getContent()));
while ((line = br.readLine()) != null) {
System.out.println(line);
Matcher m = Pattern.compile(".*\"youtubeId\": \"([A-Za-z0-9-]+)\".*").matcher(line);
if (m.matches()) {
video_id = m.group(1);
System.out.println("Video ID: " + video_id);
}
}
response.close();
sendYummyAjaxData2();
} catch (IOException ex) {
ex.printStackTrace();
}
}
private void sendYummyAjaxData2() throws ClientProtocolException, IOException {
HttpPost httpPost = new HttpPost("https://www.youtube.com/yummy_ajax");
Vector<BasicNameValuePair> fields = new Vector<BasicNameValuePair>();
fields.add(new BasicNameValuePair("action_report", "1"));
fields.add(new BasicNameValuePair("event_type", "REGISTRATION_INFO_RECEIVED"));
fields.add(new BasicNameValuePair("frontend_id", "web_upload:" + web_upload + ":0"));
fields.add(new BasicNameValuePair("version", "1"));
fields.add(new BasicNameValuePair("video_id", video_id));
fields.add(new BasicNameValuePair("session_token", identity_token));
httpPost.setEntity(new UrlEncodedFormEntity(fields));
CloseableHttpResponse response = hc.execute(httpPost);
HttpEntity entity = response.getEntity();
String line = "";
br = new BufferedReader(new InputStreamReader(entity.getContent()));
while ((line = br.readLine()) != null) {
System.out.println(line);
}
response.close();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question