Tuesday, December 13, 2011

Login to FB from java

package test;

import javax.ws.rs.core.MultivaluedMap;

import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.WebResource.Builder;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.core.util.MultivaluedMapImpl;

public class CallWS {

public static void main(String[] args) throws Exception {

ClientConfig config = new DefaultClientConfig();
com.sun.jersey.api.client.Client client = com.sun.jersey.api.client.Client.create(config);


MultivaluedMap formData = new MultivaluedMapImpl();


formData.add("charset_test","€,´,€,´,水,Д,Є");
formData.add("charset_test","€,´,€,´,水,Д,Є");
formData.add("default_persistent","0");
formData.add("display","");
formData.add("email","YOUR_FACEBOOK_ID");
formData.add("legacy_return","1");
formData.add("login","Log In");
formData.add("lsd","");
formData.add("lsd","");
formData.add("pass","YOUR_FACEBOOK_PASSWORD");
formData.add("return_session","0");
formData.add("session_key_only","0");
formData.add("trynum","2");
System.out.println(formData.toString());

WebResource resource = client.resource("https://www.facebook.com/login.php?login_attempt=1");
// for GET
//ClientResponse response = resource.type("application/x-www-form-urlencoded").get(ClientResponse.class);
Builder builder = resource.type("application/x-www-form-urlencoded");


// for POST
ClientResponse response = resource.queryParams(formData).post(ClientResponse.class, formData);
//ClientResponse response = resource.type("application/x-www-form-urlencoded").post(ClientResponse.class, formData);

String en = response.getEntity(String.class);
System.out.println(en);
System.out.println("oks");
}
}

No comments:

Post a Comment

Disqus for yogi's talk

comments powered by Disqus