我需要从java桌面应用程序连接和验证用户,我尝试过使用facebookjsonclient和facebookRestclient的facebook-java-api,但无法获取会话密钥。是否有任何Facebook的变化,我们无法连接,或者是否有其他最好的Java API或示例如何连接。我的代码是如何将Facebook与java桌面应用程序连接
private static void getUserID(String email, String password){
String session = null;
try {
HttpClient http = new HttpClient();
http.getHostConfiguration().setHost("www.facebook.com");
String api_key = "key";
String secret = "sec";
FacebookJaxbRestClient client = new FacebookJaxbRestClient(api_key, secret);
System.out.println("====>"+client.isDesktop());
String token = client.auth_createToken();
System.out.println(" :::::::"+token);
System.out.println(" :::::::::: "+token);
PostMethod post = new PostMethod("/login.php?");
post.addParameter("api_key", api_key);
post.addParameter("email", email);
post.addParameter("pass", password);
int postStatus = http.executeMethod(post);
System.out.println("url : " + post.getURI());
System.out.println("Response : " + postStatus);
for (Header h : post.getResponseHeaders()) {
System.out.println(h);
}
session = client.auth_getSession(token); // Here I am getting error
System.out.println("Session string: " + session);
long userid = client.users_getLoggedInUser();
//System.out.println("User Id is : " + userid);*/
} catch (FacebookException fe) {
fe.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
}
对于初学者,请转到http://restfb.com/和OAuth 2.0。 – 2012-03-14 10:36:52
理查德甚至使用OAuth 2.0我还没有找到从Java桌面应用获取OAuth 2.0令牌的方法。所以你的评论并没有真正帮助回答你如何从桌面Java获得access_token的问题? – haskovec 2012-04-26 16:55:05