2013-10-26 111 views
0

您好我嘗試在我的應用中添加public_stream權限。我打印我的會議iformation在我的consol,我觀察當我添加公共權限時,我的會話狀態是CLOSED_LOGIN_FAILED,當我刪除此權限在OPENING會話狀態,我已設置其他讀取權限。無法添加publish_stream權限

這是我的代碼:

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    uiHelper = new UiLifecycleHelper(getActivity(), callback); 
    uiHelper.onCreate(savedInstanceState); 
} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 

    View view = inflater.inflate(R.layout.facebook_login_view, container, 
      false); 

    facebookButton = (LoginButton) view.findViewById(R.id.facebookAuth); 
    facebookButton.setFragment(LoginAuthFragment.this); 
    //facebookButton.setReadPermissions("email", "user_birthday"); 
    facebookButton.setPublishPermissions("publish_stream", "email", "user_birthday"); 

    return view; 
} 
private Session.StatusCallback callback = new Session.StatusCallback() { 
    @Override 
    public void call(Session session, SessionState state, Exception exception) { 
      onSessionStateChange(session, state, exception); 
    } 
}; 

private void onSessionStateChange(Session session, SessionState state, Exception exception) { 
    System.out.println(session); 
    System.out.println("Access token: "+session.getAccessToken()); 

final User u = new User(); 

     if(session.isOpened()){ 
      System.out.println("OK"); 
      final String subscribe; 
      if(receiveMail.isChecked()){ 
       subscribe = "1"; 
      }else{ 
       subscribe = "0"; 
      } 

      final String access_token=session.getAccessToken(); 

      Request request = Request.newMeRequest(session, new Request.GraphUserCallback() { 

       @Override 
       public void onCompleted(GraphUser user, Response response) { 
          if (user != null) { 

           String firstName = user.getFirstName(); 
           String lastName = user.getLastName(); 
           String userName = "fb_user_"+user.getId(); 
           String facebook_id = user.getId(); 
           String birthday = user.getBirthday(); 
           String email = user.asMap().get("email") 
             .toString(); 
           String response1 = u.checkFacebookUser(
             userName, facebook_id, access_token, 
             birthday, email, subscribe, firstName, lastName); 

           if (response1.equals("GREEN")) { 
            prefs.setTokenData(u.getToken(), 
              u.getCreatedAt(), u.getExpires()); 
            Intent loggedIn = new Intent(getActivity().getApplicationContext(), 
              MainActivity.class); 
            startActivity(loggedIn); 
            getActivity().finish(); 
           } else if (response1.equals("RED")) { 
            Toast.makeText(
              getActivity() 
                .getApplicationContext(), 
              "Unknown error", Toast.LENGTH_LONG) 
              .show(); 
           } 

          } 

       } 
      }); 
      Request.executeBatchAsync(request); 
     } 
} 

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    uiHelper.onActivityResult(requestCode, resultCode, data); 
} 

@Override 
public void onSaveInstanceState(Bundle outState) { 
    super.onSaveInstanceState(outState); 
    uiHelper.onSaveInstanceState(outState); 
} 

@Override 
public void onResume() { 
    super.onResume(); 
    Session session = Session.getActiveSession(); 

    if (session != null && 
      (session.isOpened() || session.isClosed())) { 
     onSessionStateChange(session, session.getState(), null); 
    } 

    uiHelper.onResume(); 
} 

@Override 
public void onPause() { 
    super.onPause(); 
    uiHelper.onPause(); 
} 

@Override 
public void onDestroy() { 
    super.onDestroy(); 
    uiHelper.onDestroy(); 
} 

這裏是我的會議時,我添加publish_stream許可

{會話狀態:CLOSED_LOGIN_FAILED,令牌:{的accessToken令牌:ACCESS_TOKEN_REMOVED權限:[]} ,appId:593058290740634}

這裏是我沒有publish_stream權限的會話:

{會話狀態:打開,令牌:{的accessToken令牌:ACCESS_TOKEN_REMOVED權限:電子郵件,user_birthday,user_friends,basic_info]},APPID:593058290740634}

回答

1

你不能要求發佈權限,而不首先得到「 basic_info「(這是一個讀取權限)。

正確的行爲方式是首先要求用戶輸入電子郵件和user_birthday權限,當您準備好發佈時(通常在某些用戶交互之後),然後請求publish_stream權限。

相關問題