我需要從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