android – facebook login无法通过发布或管理权限(email)发送读取授权请求

概述我有一个按钮点击登录Facebook,但有时这个代码无法工作.抛出异常:造成: com.facebook.FacebookException: Cannot pass a publish or manage permission (email) to a request for read authorization 这是我的活动代码: public class FacebookLoginActiv 我有一个按钮点击登录Facebook,但有时这个代码无法工作.抛出异常:造成:
com.facebook.FacebookException: Cannot pass a publish or manage permission (email) to a request for read authorization

这是我的活动代码:

public class FacebookLoginActivity extends Activity {    private final static String TAG="FB";    private static final List<String> PERMISSIONS=Arrays.asList("email","user_likes","user_status");    private Session.StatusCallback statusCallback=new SessionStatusCallback();    private GraphUser user = null;    private Bundle bundle;    private Intent myIntent;    private Session session;    private static FacebookLoginActivity instance=new FacebookLoginActivity();    @OverrIDe    public voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        if(bundle==null){            bundle=new Bundle();        }        Log.v(TAG,"in FB onCreate method");        myIntent = this.getIntent();        requestwindowFeature(Window.FEATURE_NO_Title);        getwindow().setFlags(WindowManager.LayoutParams.FLAG_FulLSCREEN,WindowManager.LayoutParams.FLAG_FulLSCREEN);        String action = ClIEntUtil.getElementValue("action");        Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);        session=openActiveSession(this,true,PERMISSIONS);        onClickLogin();    }    public voID onClickLogin() {        Log.v(TAG,"click login btn");        session = Session.getActiveSession();        if (!session.isOpened() && !session.isClosed()) {            OpenRequest openRequest=new Session.OpenRequest(this);            openRequest.setPermissions(PERMISSIONS);            openRequest.setCallback(statusCallback);            openRequest.setDefaultAudIEnce(SessionDefaultAudIEnce.FRIENDS);            openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);            session.openForPublish(openRequest);        } else {            Log.v(TAG,"open active session");            Session.openActiveSession(this,statusCallback);        }    }    @OverrIDe    public voID onStart() {        super.onStart();        Log.v(TAG,"onStart method to add  fb Callback");        Session.getActiveSession().addCallback(statusCallback);    }    @OverrIDe    public voID onStop() {        super.onStop();        Log.v(TAG,"onStop method to remove fb callback");        Session.getActiveSession().removeCallback(statusCallback);    }    @OverrIDe    public voID onActivityResult(int requestCode,int resultCode,Intent data) {        super.onActivityResult(requestCode,resultCode,data);        Log.v(TAG,"onActivityResult method to call Fb Session");        Session.getActiveSession().onActivityResult(this,requestCode,data);    }    @OverrIDe    protected voID onSaveInstanceState(Bundle outState) {        super.onSaveInstanceState(outState);        Session session=Session.getActiveSession();        Session.saveSession(session,outState);    }    private static Session openActiveSession(Activity activity,boolean allowLoginUI,List<String> permissions) {        OpenRequest openRequest = new OpenRequest(activity).setPermissions(permissions);        Session session = new Session.Builder(activity).build();        if (SessionState.CREATED_TOKEN_LOADED.equals(session.getState()) || allowLoginUI) {            Session.setActiveSession(session);            session.openForPublish(openRequest);            return session;        }        return null;    }    private class SessionStatusCallback implements Session.StatusCallback {        @OverrIDe        public voID call(Session session,SessionState state,Exception exception) {            Log.v(TAG,"in StatusCallback call method exception is:"+ exception);            Log.v(TAG,"session state is:"+session.isOpened());            if(user != null) {                Log.v(TAG,"fb user is exist todo login yyy");                login();                finish();                Log.v(TAG,"finish fb activity");                return;            }            if(session.isOpened()) {                Log.v(TAG,"session is opened to call FB Request");                Request.executeMeRequestAsync(session,new Request.GraphUserCallback() {                    @OverrIDe                    public voID onCompleted(GraphUser me,Response response) {                        Log.v(TAG,"in GraphUserCallback onCompleted method");                        Log.v(TAG,"GraphUser has value:"+(user!=null));                        if(me != null) {                            user=me;                            login();                        }                        finish();                        Log.v(TAG,"finish fb activity");                    }                });            }else{                Log.v(TAG,"session is not open");                if(exception !=null && exception.toString().contains("Canceled")){                    Log.v(TAG,"cancle login");                    bundle.putInt("code",RespondCode.CANCLE);                    myIntent.putExtras(bundle);                    setResult(Activity.RESulT_OK,myIntent);                    finish();                }            }        }    }       }
解决方法 您不能调用openForPublish,除非您的应用程序已经被首先授予了基本权限.

将您的PERMISSIONS列表分成PERMISSIONS_READ和PERMISSIONS_PUBliSH,并将“电子邮件”放入PUBliSH方面.然后调用openForRead,然后在会话打开时requestNewPublishPermissions.

总结

以上是内存溢出为你收集整理的android – facebook login无法通过发布或管理权限(email)发送读取授权请求全部内容,希望文章能够帮你解决android – facebook login无法通过发布或管理权限(email)发送读取授权请求所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1131565.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存