如何处理activityresult上的twitter和facebook请求代码。

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

       // If request code of facebook than i will call other function and if
       // request code of twitter than i will call some other function but
       // how i can  seprate both by request code.

}

最佳答案

你有两个选择:
1)单击FB或Twitter按钮时,将布尔值设置为true,并检查单击了哪个按钮以确定要调用的方法。

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

  if (fb_clicked == true)
 {
     //call the callback manager's onActivityResult
 }
 else if(twitter_clicked == true)
{
     //call the twitter login button's onActivityResult
}
}

2)或者可以使用auth令牌来确定单击哪个按钮,因为单击loginbutton时将生成auth令牌(twitter或facebook,另一个应为空)
   @Override
   protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     super.onActivityResult(requestCode, resultCode, data);

     if (requestCode == TwitterAuthConfig.DEFAULT_AUTH_REQUEST_CODE) {
    // Twitter request code
    // TwitterLoginButton::onActivityResult(requestCode::int, resultCode::int, data::Intent);
} else {
    // Use Facebook callback manager here
    // CallbackManager::onActivityResult(requestCode::int, resultCode::int, data::Intent);
}
}

编辑:用第二个选项的Patrick W's答案更新了代码,这是一个更好的方法,正如他提到的,这个解决方案适用于com.twitter.sdk.android:twitter:1.14.1和更高版本。

10-07 16:22
查看更多