【发布时间】: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