problem to create session of facebook login

Posted by khoyendra on Stack Overflow See other posts from Stack Overflow or by khoyendra
Published on 2010-06-09T13:36:45Z Indexed on 2010/06/09 13:42 UTC
Read the original article Hit count: 504

Filed under:
import com.facebook.api.FacebookRestClient;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpClientParams;

public class FaceLogin {
    public FaceLogin(){
        getUserID("xxxxxx", "xxxxxx");
    }
    private static void getUserID(String email, String password){
        String session = null;
        try {
            HttpClient http = new HttpClient();
            http.setParams(new HttpClientParams());                             
            http.setState(new HttpState());
            String api_key = "API KEY";                 
            String secret  = "SECRETS";                 
            FacebookRestClient client = new FacebookRestClient(api_key, secret);
            client.setIsDesktop(true);

            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("lsd","8HYdi"));
            post.addParameter(new NameValuePair("locale","en_US"));
            post.addParameter(new NameValuePair("persistent","1"));
            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();

        }
    }
    public static void main(String k[])
    {
        FacebookLogin facebookLoginObj=new FacebookLogin();
    }
}

here i have to find some error when i create session error is

run:
Get=org.apache.commons.httpclient.methods.GetMethod@17ec9f7
Token =0c578e0692ae04327cd29a4beede48e3
Jun 8, 2010 7:04:48 PM org.apache.commons.httpclient.HttpMethodBase processResponseHeaders
WARNING: Cookie rejected: "$Version=0; $Domain=deleted; $Path=/; $Domain=.facebook.com". Cookie name may not start with $
Response : 200
Jun 8, 2010 7:04:48 PM org.apache.commons.httpclient.HttpMethodBase processResponseHeaders
WARNING: Cookie rejected: "$Version=0; $Path=deleted; $Path=/; $Domain=.facebook.com". Cookie name may not start with $
Facebook returns error code 100
  - v -> 1.0
  - auth_token -> 0c578e0692ae04327cd29a4beede48e3
  - method -> facebook.auth.getSession
com.facebook.api.FacebookException: Invalid parameter
  - call_id -> 1276004088734
  - api_key -> f7cb1e48c383ef599da9021fc4dec322
  - sig -> 8b7f0a5394b25551ab3cf1487ac0da00
        at com.facebook.api.FacebookRestClient.callMethod(FacebookRestClient.java:828)
        at com.facebook.api.FacebookRestClient.callMethod(FacebookRestClient.java:606)        at com.facebook.api.FacebookRestClient.callMethod(FacebookRestClient.java:606)

        at com.facebook.api.FacebookRestClient.auth_getSession(FacebookRestClient.java:1891)
        at facebookcrawler.FacebookLogin.getUserID(FacebookLogin.java:81)
        at facebookcrawler.FacebookLogin.<init>(FacebookLogin.java:24)
        at facebookcrawler.FaceLogin.main(FaceLogin.java:80)
BUILD SUCCESSFUL (total time: 7 seconds)

© Stack Overflow or respective owner

Related posts about java