为什么在使用Facebook登录按钮调用CallbackManager上的onActivityResult()后绝对没有任何反应?(Why absolutely nothing happens aft

编程入门 行业动态 更新时间:2024-10-26 07:27:57
为什么在使用Facebook登录按钮调用CallbackManager上的onActivityResult()后绝对没有任何反应?(Why absolutely nothing happens after calling onActivityResult() on the CallbackManager using the Facebook Login Button?)

我一直试图弄清楚如何解决这个问题但是没有成功。

这里的问题是在点击登录按钮后,它正常加载Facebook活动,当它完成时,我的活动收到活动结果并通知CallbackManager(所有文档中描述)。

不幸的是,从这一点来看没有任何事情发生,注册的FacebookCallback没有执行任何方法,甚至没有记录一行来通知错误。

以下是涉及的文件:

public class LoginActivity extends Activity CallbackManager callbackManager; LoginButton loginFacebook; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(this); setContentView(R.layout.activity_login); ... callbackManager = CallbackManager.Factory.create(); loginFacebook = (LoginButton) findViewById(R.id.login_button); loginFacebook.setReadPermissions("public_profile","email"); loginFacebook.registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { ... (This is never executed) } @Override public void onCancel() { ... (Not executed) } @Override public void onError(FacebookException e) { ... (Not executed either) } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { callbackManager.onActivityResult(resultCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data); } ... }

而activity_login.xml包含这样的按钮

<com.facebook.login.widget.LoginButton android:id="@+id/login_button" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center_horizontal"/>

我还在我的android清单文件中添加了Facebook Activity和APP ID

<activity android:name="com.facebook.FacebookActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:label="@string/app_name" android:theme="@android:style/Theme.Translucent.NoTitleBar" /> <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id" />

以及facebook应用程序中的android app键。

希望为此找到解决方案,非常感谢你。

I've been trying to figure out how to solve this but was unsuccessful.

The problem here is after clicking the login button, it loads the Facebook Activity normally, and when it finishes, my activity receives the activity result and notifies the CallbackManager (all as described in the docs).

Unfortunately nothing happens from this point, no method from the registered FacebookCallback is executed, and not even a line is logged to inform of an error.

Here are the involved files:

public class LoginActivity extends Activity CallbackManager callbackManager; LoginButton loginFacebook; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(this); setContentView(R.layout.activity_login); ... callbackManager = CallbackManager.Factory.create(); loginFacebook = (LoginButton) findViewById(R.id.login_button); loginFacebook.setReadPermissions("public_profile","email"); loginFacebook.registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { ... (This is never executed) } @Override public void onCancel() { ... (Not executed) } @Override public void onError(FacebookException e) { ... (Not executed either) } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { callbackManager.onActivityResult(resultCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data); } ... }

And activity_login.xml includes the button like this

<com.facebook.login.widget.LoginButton android:id="@+id/login_button" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center_horizontal"/>

I also added the Facebook Activity and APP ID in my android manifest file

<activity android:name="com.facebook.FacebookActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:label="@string/app_name" android:theme="@android:style/Theme.Translucent.NoTitleBar" /> <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id" />

As well as the android app key in the facebook application.

Hope figures out a solution for this, thank you very much.

最满意答案

好的,我现在看到了。 这可能是错的

callbackManager.onActivityResult(resultCode, resultCode, data);

请参阅resultCode两次输入。 你想要做的是:

callbackManager.onActivityResult(requestCode, resultCode, data);

Ok I see now. This is probably wrong

callbackManager.onActivityResult(resultCode, resultCode, data);

See resultCode is entered twice. What you want to do is:

callbackManager.onActivityResult(requestCode, resultCode, data);

更多推荐

本文发布于:2023-08-02 23:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1382455.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:没有任何   按钮   onActivityResult   CallbackManager   Facebook

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!