如何在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.
}
答案 0 :(得分:5)
从com.twitter.sdk.android:twitter:1.14.1
开始,你可以使用:
@Override
public 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);
}
}
答案 1 :(得分:2)
您有两个选择:
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 Token确定单击了哪个按钮,因为当您单击LoginButton(Twitter或Facebook并且其他应该为null)时将生成auth令牌
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (AccessToken.getCurrentAccessToken() !=null)
//call the callback manager's onActivityResult
else
{
//call the twitter login button's onActivityResult
}
}