【问题标题】:Youtube like (rating) not workingYoutube 喜欢(评分)不起作用
【发布时间】:2016-03-31 09:00:33
【问题描述】:

我已登录并获得身份验证令牌,但是当我单击“赞”按钮时,youtube 评级不起作用。我还需要做什么才能让它发挥作用?如果我在网络浏览器中使用它要求授权并执行的 url,那么它就可以工作。但从应用程序来看,它还没有发生。此外,我还设置了所有必需的客户端 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 错误。 PS我已经登录并获得了令牌值。所以我猜它不应该是身份验证错误。响应长度也为空,响应正文也是如此。因此,谷歌的欺诈检测部分在这里无效。

【问题讨论】:

  • 你有什么异常吗?
  • 不...什么都没有....我登录了,访问令牌也是如此,但没有。的喜欢保持不变
  • 你好 @Berger 现在给出 403 Forbidden 异常。

标签: java youtube codenameone


【解决方案1】:

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

请注意,调用此类 API 可能具有挑战性,因为 Google 可能已进行欺诈检测,并且可能已将您标记为试图规避类似系统的人。

【讨论】:

  • 我更新了上面网络监视器的响应,请看一下。
  • 响应正文中没有内容吗?它说有 994 个字节,所以它给出了一些答案
  • 如果我尝试读取响应,它会提供如上更新的错误输出。
  • 将其读入字符串并打印该字符串。响应应列在网络监视器中
  • 对不起 Shai,我的错误我开始知道我使用了错误的 API 进行评分。我更新了上面的右边,但它给出了 403 Forbidden 错误。 PS我已经登录并获得了令牌值。所以我猜它不应该是身份验证错误。
猜你喜欢
  • 2013-05-26
  • 1970-01-01
  • 2016-03-24
  • 1970-01-01
  • 2020-10-07
  • 1970-01-01
  • 2012-01-24
  • 2018-02-26
  • 2017-06-07
相关资源
最近更新 更多