Facebook中没有电子邮件身份验证

时间:2013-12-12 07:57:30

标签: android facebook

MainActivity.java

   facebookbutton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if(fb.isSessionValid())
                {
                    try {
                        fb.logout(getApplicationContext());
                        updatebuttonimage();
                    } catch (MalformedURLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
                else
                {
                    fb.authorize(MainActivity.this,new String[]{"email"},new DialogListener() {

                        @Override
                        public void onFacebookError(FacebookError e) {
                            Toast.makeText(MainActivity.this,"FacebookError",Toast.LENGTH_SHORT).show();

                        }

                        @Override
                        public void onError(DialogError e) {
                            Toast.makeText(MainActivity.this,"Error",Toast.LENGTH_SHORT).show();

                        }

                        @Override
                        public void onComplete(Bundle values) {
                            Editor editor = sp.edit();
                            editor.putString("access_token",fb.getAccessToken());
                            editor.putLong("access_expires",fb.getAccessExpires());
                            editor.commit();
                            updatebuttonimage();
                        }

                        @Override
                        public void onCancel() {
                            Toast.makeText(MainActivity.this,"Cancelled",Toast.LENGTH_SHORT).show();

                        }
                    });
                }

            }
        });

    }

    @SuppressWarnings("deprecation")
    private void updatebuttonimage()
    {
        String app_id = getString(R.string.app_id);
        fb = new Facebook(app_id);
        String jsonUser = null;
        if(fb.isSessionValid())
        {
            facebookbutton.setImageResource(R.drawable.button3);
            pic.setVisibility(ImageView.VISIBLE);

        }
        else
        {
            facebookbutton.setImageResource(R.drawable.login);
            pic.setVisibility(ImageView.INVISIBLE);
        }

    }

logcat的:

12-12 13:40:56.023: D/dalvikvm(13407): GC_CONCURRENT freed 373K, 48% free 3084K/5831K, external 852K/1339K, paused 5ms+7ms
12-12 13:41:55.156: D/dalvikvm(13407): GC_CONCURRENT freed 455K, 48% free 3099K/5959K, external 714K/1226K, paused 4ms+4ms
12-12 13:45:16.789: W/com.facebook.Session(13407): Should not pass a read permission (email) to a request for publish or manage authorization

我已在authorize方法中添加了电子邮件身份验证,但在登录时不会要求身份验证。此外,图像按钮(facebookbutton)不会更新。它在updateButtonImage()中实现。将非常感谢帮助。提前致谢。

0 个答案:

没有答案