简体   繁体   English

onActivityResult处理Facebook和Twitter登录

[英]onActivityResult to handle both facebook and twitter login

In facebook, Im asked to do: 在Facebook中,我要求这样做:

 protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode, resultCode, data);
}

In Twitter, Im asked to do: 我在Twitter中要求执行以下操作:

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

    // Pass the activity result to the login button.
    loginButton.onActivityResult(requestCode, resultCode, data);
}

How to combine them, and what is onActivityResult used for? 如何将它们组合在一起,以及onActivityResult的作用是什么? To tell button text to change to ":logout"? 告诉按钮文本更改为“:logout”?

What you can do is Identify onActivityResult on requestCode 您可以做的是在requestCode上标识onActivityResult

See this link for Twitter Request code 查看此链接以获取Twitter请求代码

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

    if(requestCode == TwitterAuthConfig.DEFAULT_AUTH_REQUEST_CODE){
        //  twitter related handling
    }else{
       // facebook related handling
    }
}

No, this is the method called after executing an Intent which your app would call. 不,这是在执行您的应用将调用的Intent之后调用的方法。 For example, a facebook login is initiated by your app, this method gets called for whatever happened to the facebook login (Failed, Cancelled etc.). 例如,Facebook登录由您的应用启动,该方法针对Facebook登录发生的任何事情(失败,取消等)被调用。 When executing an intent you get to pass a Request Code to the Intent parameters the same request code is then passed to this onActivityResult method. 执行意图时,您需要将请求代码传递给Intent参数,然后将相同的请求代码传递给此onActivityResult方法。 You can use this request code to determine which results are the intent data received from (whether from facebook or twitter or others. 您可以使用此请求代码来确定哪些结果是从(无论是从facebook或twitter还是其他人)接收到的意图数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM