开发者

Facebook sdk (Single Sign On) didn't work on the device

I use the single sign on in my application (http://developers.facebook.com/docs/mobile/android/build/). It seems working fine on the emulator (i log in succefully and get the access_token). But in my Nexus S, the webview shows up, but I always get "login failed".

There is my code:

((Button)findViewById(R.id.BtnFacebook)).setOnClickListener(new OnClickListener(){

        public void onClick(View v) {

            //startActivity(intentLoginFacebook);

            facebook.authorize(Login.this, new String[] {"user_about_me","user_activities","user_birthday","user_education_history","user_events","user_groups","user_hometown","user_interests","user_likes","user_location","user_religion_politics","user_status","user_website","user_work_history","read_requests","read_stream","friends_events","email","create_event","manage_friendlists","offline_access","rsvp_event"}, new DialogListener() {
                @Override
                public void onComplete(Bundle values) {

                    String id = "开发者_如何转开发";
                    String access_token = facebook.getAccessToken();
                    System.out.println("ACCESSTOKENNNN:" + access_token);

                    try {
                        String response = facebook.request("me");

                        JSONObject obj = new JSONObject(response);
                        id = obj.getString("id");
                        System.out.println("response: "+response);

                    } catch (IOException ex) {
                        Log.d("Facebook", ex.getMessage());
                    } catch (Exception e) {
                        Log.d("Facebook", e.getMessage());
                    }


                    //Verification du login/password
                    new LoginFacebook().execute(id,access_token);
                    System.out.println("IDDDDDDDD:" + id);              

                }

                @Override
                public void onFacebookError(FacebookError error) {
                    Toast.makeText(getApplicationContext(), "Facebook error: login failed", Toast.LENGTH_LONG).show();

                }

                @Override
                public void onCancel() {
                }

                @Override
                public void onError(DialogError e) {
                    // TODO Auto-generated method stub
                    Toast.makeText(getApplicationContext(), "Login failed", Toast.LENGTH_LONG).show();

                }
            });

        } 
            });

Thanks for your help!


Most likely the SDK stores your access_token and expires_in paramters in SharedPreferences. You need to log the detailed error. If you get OAuth exception on an API call you need to delete access_token from SharedPreferences and simply reauthorize.

hope this helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜