我试图在Codename one应用程序成功登录后请求用户信息,但是当登录用户重定向到应用程序后,但没有得到任何响应。
以下是我的代码:
linked.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
Oauth2 auth2 = new Oauth2("https://www.linkedin.com/oauth/v2/authorization",
"XXXXXXXXXX",
"https://www.codenameone.com","",
"https://www.linkedin.com/oauth/v2/accessToken",
"XXXXXXXXXX");
//auth2.authenticate();
auth2.showAuthentication(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
AccessToken token = (AccessToken) evt.getSource();
JSONObject object = new JSONObject(token);
try {
TOKEN = object.getString("token");
Log.p(TOKEN);
ConnectionRequest linkedinreq = new ConnectionRequest(){
@Override
protected void readResponse(InputStream input) throws IOException {
Log.p(input.toString());
}
};
linkedinreq.setPost(false);
linkedinreq.setUrl("https://api.linkedin.com/v1/people/~:(id,num-connections,picture-url)");
linkedinreq.addArgumentNoEncoding("oauth2_access_token", TOKEN);
linkedinreq.addArgumentNoEncoding("format", "json");
NetworkManager.getInstance().addToQueue(linkedinreq);
} catch (JSONException ex) {
ex.printStackTrace();
}
}
});
Oauth2.setBackToParent(true);
}
});
显示空响应的网络监视器快照
输出显示在控制台
[Network Thread] 0:0:1,12 - com.codename1.impl.javase.JavaSEPort$67@41ca2b3e
答案 0 :(得分:1)
覆盖此消息后,您可以收到任何错误消息 并调用setreadResponseErrors(true);这将显示错误消息和响应代码。
linkedinreq.setReadResponseForErrors(true);
@Override
protected void handleErrorResponseCode(int code, String message) {
System.out.println("code: " + code + "message: " + message);
}