Android - 附加到 Facebook.authorize() 的 DialogListener 中的方法未命中
我正在尝试将 Facebook Android SDK 集成到我的应用程序中,但我似乎无法进行最基本的身份验证。我已经有了我的项目设置、我的 Facebook 应用程序 ID,以及所需的一切。
我用一个简单的 OnClickListener() 启动 Facebook 身份验证:
signIn_Facebook.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
Log.i("MyTag", "Facebook authorize about to start.");
facebook.authorize(SignIn.this, new FacebookLoginDialogListener());
}
});
我的问题是 DialogListener 中的任何方法都没有被调用:
private class FacebookLoginDialogListener implements DialogListener {
public void onComplete(Bundle values)
{
Log.i("MyTag", "Facebook authorize complete.");
}
@Override
public void onFacebookError(FacebookError error) {
Log.i("MyTag", "Facebook authorize facebook error.");
}
@Override
public void onError(DialogError e)
{
Log.i("MyTag", "Facebook authorize dialog error.");
}
@Override
public void onCancel()
{
Log.i("MyTag", "Facebook authorize cancel.");
}
}
当此代码在应用程序上运行时,Facebook 对话框打开,您可以登录,然后它只是关闭 - 没有错误 - 但是 FacebookLoginDialogListener 类中的任何日志消息(或断点)都不会被调用。
我觉得我好像错过了一些非常明显的东西。谢谢...
已解决
只需添加:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
facebook.authorizeCallback(requestCode, resultCode, data);
}
I'm trying to integrate the Facebook Android SDK in my app, but I can't seem to get the most basic authentication working. I've got my project setup, my Facebook App ID, everything as required.
I kick off the Facebook authentication with a simple OnClickListener():
signIn_Facebook.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
Log.i("MyTag", "Facebook authorize about to start.");
facebook.authorize(SignIn.this, new FacebookLoginDialogListener());
}
});
My problem is that none of the methods in the DialogListener ever get called:
private class FacebookLoginDialogListener implements DialogListener {
public void onComplete(Bundle values)
{
Log.i("MyTag", "Facebook authorize complete.");
}
@Override
public void onFacebookError(FacebookError error) {
Log.i("MyTag", "Facebook authorize facebook error.");
}
@Override
public void onError(DialogError e)
{
Log.i("MyTag", "Facebook authorize dialog error.");
}
@Override
public void onCancel()
{
Log.i("MyTag", "Facebook authorize cancel.");
}
}
When this code runs on the app, the Facebook dialog opens up, you can sign in, and then it just closes - no errors - however none of the log message (or breakpoints) in the FacebookLoginDialogListener class ever get called.
I feel as though I'm missing something really obvious. Thanks...
SOLVED
Just needed to add:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
facebook.authorizeCallback(requestCode, resultCode, data);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
私人 Facebook mFb;
私有字符串[] mPermissions;
mFb.authorize(mActivity, mPermissions, new LoginDialogListener());
如果您想要一个示例,请查看 https://github.com/facebook/facebook-android-sdk/blob/master/examples/simple/src/com/facebook/android/LoginButton.java
还有什么,尽管问;)
try this:
private Facebook mFb;
private String[] mPermissions;
mFb.authorize(mActivity, mPermissions, new LoginDialogListener());
If you want an example check out https://github.com/facebook/facebook-android-sdk/blob/master/examples/simple/src/com/facebook/android/LoginButton.java
Anything else, just ask ;)