Youtube喜欢(评级)不工作

时间:2016-03-31 09:00:33

标签: java youtube codenameone

我已登录并获取身份验证令牌,但是当我点击“赞”按钮时,youtube评级无效。我还需要做些什么才能让它发挥作用?如果我在网络浏览器中使用网址,它要求授权和执行,然后它的工作原理。但是从应用程序来看,它还没有发生。此外,我还设置了所有必需的客户端ID,客户端密码等。

connectionForYoutubeData();

f.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
Button signIn = new Button("signIn");
Button like = new Button("Like");
like.setText("Like: " + likeCount);

Container mainContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
mainContainer.add(signIn);
mainContainer.add(like);
f.add(mainContainer);

signIn.addActionListener((e) -> {
    String clientId = "704790222159-n1cpb3g1q3plirslu5739apc0gnnv4pp.apps.googleusercontent.com";
    String redirectURI = "https://www.youtube.com/";
    String clientSecret = "q_cxGCCbX5GVC99kxgstjksB";
    Login gc = GoogleConnect.getInstance();
    gc.setClientId(clientId);
    gc.setRedirectURI(redirectURI);
    gc.setClientSecret(clientSecret);
    gc.setCallback(new LoginCallback() {
        @Override
        public void loginFailed(String errorMessage) {
            like.addActionListener((c) -> {
                Label newLabel = new Label("beck unsuccess");
                f.add(newLabel);
            });
        }
        @Override
        public void loginSuccessful() {
            Dialog.show("Logged In", "you are currently logged in ", "OK", null);
        }
    });
    if (!gc.isUserLoggedIn()) {
        gc.doLogin();
    } else {
        token = gc.getAccessToken().getToken();
    }
});

like.addActionListener((e) -> {
    ConnectionRequest cr = new ConnectionRequest() {
        @Override
        protected void readResponse(InputStream input) throws IOException {
            super.readResponse(input);
        }
        @Override
        protected void postResponse() {
            super.postResponse();
        }
    };
    cr.setPost(true);
    cr.setUrl("https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.videos.rate?" + "id=" + "Z98hXV9GmzY" + "&rating=like" + "&access_token=" + token + "&key=AIzaSyCAETrMkZeJ_nTq4ZdP1Jq6BFtA_11TR6I"); 
    cr.setDuplicateSupported(true);
    NetworkManager.getInstance().addToQueueAndWait(cr);
});
f.revalidate();

登录回复标题:

Transfer-Encoding=[chunked]
null=[HTTP/1.1 200 OK]
Alt-Svc=[quic=":443"; ma=2592000; v="32,31,30,29,28,27,26,25"]
Server=[GSE]
X-Content-Type-Options=[nosniff]
Pragma=[no-cache]
Date=[Fri, 01 Apr 2016 04:17:24 GMT]
Alternate-Protocol=[443:quic]
Accept-Ranges=[none]
X-Frame-Options=[SAMEORIGIN]
Cache-Control=[no-cache, no-store, max-age=0, must-revalidate]
Vary=[Origin,Accept-Encoding, X-Origin]
Expires=[Fri, 01 Jan 1990 00:00:00 GMT]
X-XSS-Protection=[1; mode=block]
Content-Type=[application/json; charset=UTF-8]

像响应标题:

X-Frame-Options=[DENY]
null=[HTTP/1.1 200 OK]
Server=[Google Frontend]
Content-Length=[994]
Date=[Fri, 01 Apr 2016 04:18:11 GMT]
Content-Type=[text/html; charset=utf-8]

更新

@Override
protected void readResponse(InputStream input) throws IOException {
 JSONParser jSONParser = new JSONParser();
 results = jSONParser.parseJSON(new InputStreamReader(input));
 System.out.println("parsed results: " + results);
    }

如果我尝试按上述方式读取响应,则会在输出中显示以下错误

Expected true for key value!
Expected true for key value!
java.lang.ArrayIndexOutOfBoundsException
Expected true for key value!
Expected true for key value!
Expected true for key value!
Expected null for key value!
Expected null for key value!
Expected null for key value!
Expected true for key value!
Expected true for key value!
Expected true for key value!
Expected true for key value!
parsed results: {}

更新2:
我发现我使用错误的API进行评分。正确的是

cr.setUrl("https://www.googleapis.com/youtube/v3/videos/rate?id=" + "kF94Jwx9ugU" + "&rating=like&access_token=" + token + "&key=xxxxxx");

但是它给出了403 Forbidden错误。 P.S我已经登录并获得了令牌值。所以我猜它不应该是auth错误。响应长度也为空,响应体也是如此。因此谷歌的欺诈检测部分在这里无效。

1 个答案:

答案 0 :(得分:0)

我注意到你没有检查对类似调用的响应,该调用可能包含JSON或数据,这些数据将指示为什么不接受此操作。我建议使用网络监视器来查看该响应。

请注意,调用此类API可能具有挑战性,因为Google可能已经进行了欺诈检测,并且可能已经将您标记为想要绕过类似系统的人。