2013-02-19 104 views
0

我正在嘗試在我的遊戲中整合Facebook以在用戶的​​牆上張貼記錄,但登錄後我得到了一個授予權限的窗口,當我接受該窗口時,我希望我的遊戲再次不做任何操作還要別的嗎。在Android中集成facebook的問題

我有一個變量(useFacebook)在啓動會話時應該成爲true或者如果會話已經開始earlier.But,喜歡它的行爲總是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; 
    }  

而這些都是我得到的畫面:

Login Permissions

感謝。

回答

0

屏幕顯示正確,在允許讀取或發佈任何數據之前,用戶需要授權您的應用程序。

想想你的onResume你應該嘗試使用Session.getActiveSession();這將使您獲得當前的活動會話。