0

我正在尝试将 facebook 集成到我的游戏中以在用户的​​墙上发布记录,但是登录后我得到一个授予权限的窗口,当我接受时,我希望我的游戏再次恢复而不做任何其他事情。

我有一个变量 ( useFacebook),它应该true在会话启动时或会话已经开始较早时变为。但是,它的行为就像往常一样false。如果我将其改为true手动,我会收到一个错误发布到 facebook。

这是相关代码:

@Override
    public void onResumeGame() {
            super.onResumeGame();

            if (mServ != null)
            {                      
                    mServ.resumeMusic();                                           
            }

            checkFaceBook();               
    } 
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        super.onActivityResult(requestCode, resultCode, data);
        Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
} 
public void checkFaceBook()
    {
    Session.openActiveSession(this, false, new Session.StatusCallback()
    {
            @Override
            public void call(Session session, SessionState state, Exception exception)
            {
            if (session.isOpened())
            {
                // Never enters here.
                    Request.executeMeRequestAsync(session, new Request.GraphUserCallback()
                    {
                                            @Override
                                            public void onCompleted(GraphUser user, Response response)
                                            {
                                                    if (user != null)
                                                    {
                            fbUsername = user.getFirstName();
                            useFacebook = true;
                                                    }
                                            }                        
                    });
            }
            }
    });
    } 
public void facebookLogin()
    {              
            Session.openActiveSession(this, true, new Session.StatusCallback()
            {  
                    @Override
                    public void call(Session session, SessionState state, Exception exception)
                    {
                    if (session.isOpened())
                    {
                       // Never enters here.
                            Request.executeMeRequestAsync(session, new Request.GraphUserCallback()
                            {
                                    @Override
                                    public void onCompleted(GraphUser user, Response response)
                                    {                                              
                                    if (user != null)
                                    {
                                            // CALLBACK: USER IS LOGGED IN
                                            // DO YOUR STUFF HERE
                                            fbUsername = user.getFirstName();
                                            useFacebook = true;

                                            facebookFeedDialog("Test");
                                    }
                                    }
                            });
                    }
                    }
            });
    } 
public void facebookFeedDialog(String message)
    {              
            Bundle params = new Bundle();
            params.putString("name", message);
            params.putString("caption", "ccccc");
            params.putString("description", "ddddd");
            params.putString("link", "https://market.android.com/details?id="+this.getApplication().getPackageName().toString());
            params.putString("picture", "http://www.myimage.com/01.jpg");

            WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(this, Session.getActiveSession(), params)).setOnCompleteListener(new OnCompleteListener() {
                    @Override
                    public void onComplete(Bundle values, FacebookException error)
                    {
                    if (error == null)
                    {
                    final String postId = values.getString("post_id");
                    if (postId != null)
                    {
                            // POSTED                              
                    }
                    else
                    {
                            // POST CANCELLED                              
                    }
                    }
                    else if (error instanceof FacebookOperationCanceledException)
                    {
                            // POST CANCELLED                              
                    }
                    else
                    {
                            // ERROR POSTING                               
                    }
                   }                 
            }).build();
            feedDialog.show();
    } 
public boolean onSceneTouchEvent(Scene pScene,
                    TouchEvent pSceneTouchEvent) {         

            if (mFB.onAreaTouched(pSceneTouchEvent, pSceneTouchEvent.getX(), pSceneTouchEvent.getY()))
            {                                              
                    mClickSnd.play();                      

                    if (useFacebook == true)
                    {                              
                            facebookFeedDialog("Test");
                    }
                    else
                    {
                            facebookLogin();                               
                    }                              

                    return true;
            }

            return false;
    }    

这些是我得到的屏幕:

登录 权限

谢谢。

4

1 回答 1

0

屏幕是正确的,用户需要在允许读取或发布任何数据之前授权您的应用程序。

想想你的 onResume 你应该尝试使用 Session.getActiveSession(); 这将为您提供当前的活动会话。

于 2013-02-19T19:19:23.737 回答