Facebook的登录为Android [英] Facebook Login for android

查看:194
本文介绍了Facebook的登录为Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图打开一个Facebook的画廊如果在登录Facebook的一样,我要求在Android的Facebook登录使用Facebook的SDK和我写这篇code:

I am trying to open a facebook gallery if is logged in in facebook else I asked for the facebook login in android using facebook sdk and I wrote this code:

Session.openActiveSession(FbGallery.this, true, new Session.StatusCallback() {
    @SuppressWarnings("deprecation")
    @Override
    public void call(final Session session, SessionState state, Exception exception) {

        System.out.println("Session:::"+session.toString());

        if(session.isOpened()){
            session.requestNewPublishPermissions(
                    new Session.NewPermissionsRequest(FbGallery.this, "user_photos"));
            Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

                @Override
                public void onCompleted(GraphUser user, Response response) {
                    Toast.makeText(getApplicationContext(), "Session is opened", Toast.LENGTH_SHORT).show();
                }
            });
        }
        else{
            Toast.makeText(getApplicationContext(), "Gone to else", Toast.LENGTH_SHORT).show();
        }
    }
});

它工作得很好,并得到登录页面,如果没有登录,但如果再被记录它运行code递归即。敬酒消息Session被打开'在这里。

It works nicely and gets login page if is not logged in but if is logged in then it runs the code recursively ie. the toast message 'Session is opened' up here.

这是什么道理。我无法理解。

What is the reason. I can't understand..

推荐答案

私人无效onClickRequest()
    {

private void onClickRequest() {

    if (this.session.isOpened() && session!=null) 
    {
        shareDialog=new ProgressDialog(MainActivity.this);
        shareDialog.setTitle("Post ON Wall");
        shareDialog.setMessage("Wait..........");
        shareDialog.setCancelable(false);

        System.out.println("Already Logged In");

        if (session.isOpened()) {
            // make request to the /me API
            Request.executeMeRequestAsync(session, new Request.GraphUserCallback() 


            {
            // callback after Graph API response with user object
            @Override
            public void onCompleted(GraphUser user, Response response) {
            if (user != null) {

                System.out.println(user.getId()+user.getName()+"........................");
                id=user.getId();
                Toast.makeText(getApplicationContext(), session.getAccessToken(), 100).show();
            }
            }
            });
            }
        //postPhoto();
    } else {
        StatusCallback callback = new StatusCallback() {
            public void call(Session session, SessionState state,
                    Exception exception) {
                if (exception != null) {
                    new AlertDialog.Builder(MainActivity.this)
                            .setTitle("Failed Login")
                            .setMessage(exception.getMessage())
                            .setPositiveButton("Ok", null)
                            .show();
                    MainActivity.this.session = createSession();
                }
            }
        };
        pendingRequest = true;
        MainActivity.this.session = createSession();


        this.session.openForRead(new Session.OpenRequest(this)
        .setCallback(callback).setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO).setPermissions(""));




    }

这篇关于Facebook的登录为Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆