try {
HttpClient http = new HttpClient();
http.setParams(new HttpClientParams()); //http.getHostConfiguration().setHost("http://www.facebook.com/");
http.setState(new HttpState());
String api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
String secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
// String appId=124812364218050; //http://www.facebook.com/developers/editapp.php?app_id=124812364218050
FacebookRestClient client = new FacebookRestClient(api_key, secret);
client.setIsDesktop(true);
// String sessionKey = request.getParameter(FacebookParam.SESSION_KEY.toString());
// boolean b = client.users_setStatus("This is a test...");
// System.out.println("User Status RESULT : " + b);
String token = client.auth_createToken();
final String loginId = "http://www.facebook.com/login.php";
GetMethod get = new GetMethod(loginId + "?api_key=" + api_key + "&v=1.0&auth_token=" +token);
System.out.println("Get="+get);
http.executeMethod(get);
PostMethod post = new PostMethod(loginId);
post.addParameter(new NameValuePair("api_key", api_key));
post.addParameter(new NameValuePair("v", "1.0"));
post.addParameter(new NameValuePair("auth_token", token));
post.addParameter(new NameValuePair("fbconnect","true"));
post.addParameter(new NameValuePair("return_session","true"));
post.addParameter(new NameValuePair("session_key_only","true"));
post.addParameter(new NameValuePair("req_perms","read_stream,publish_stream"));
post.addParameter(new NameValuePair("email", email));
post.addParameter(new NameValuePair("pass", password));
System.out.println("Token ="+token);
int postStatus = http.executeMethod(post);
System.out.println("Response : " + postStatus);
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 (Exception e) {
e.printStackTrace();
}
please solve my problem
i cannot create session of facebook.