简体   繁体   English

Facebook身份验证在仿真器上工作,但不在物理设备上

[英]Facebook Authentication working on Emulator, But not on physical device

Hey everyone just recently developed my first android app that logs into facebook and tries to status update Without the dialog box, using the graph API. 嘿大家刚刚开发了我的第一个登录到Facebook的Android应用程序并尝试状态更新没有对话框,使用图形API。 The code below is the authorization code (which was on the fbook dev site itself) and it worked fine for me all along, until recently. 下面的代码是授权代码(它位于fbook开发站点本身),它一直对我很好,直到最近。 Now my app logins in fine on my emulator but when I export the APK file and put it on my phone it gives me 'authentication error". Can someone explain this? It just doesn't show me the login page anymore, After I created a new keystore and hashkey AND updated that hashkey on my dev app page on facebook as usual. 现在我的应用程序在我的模拟器上正常登录,但当我导出APK文件并将其放在我的手机上时,它会给我“身份验证错误”。有人可以解释一下吗?它只是不再向我显示登录页面,在我创建之后一个新的密钥库和hashkey并像往常一样在facebook上的我的开发应用页面上更新了这个hashkey。

I think it's due to the keyhash etc, but I dont understand that well enough to figure out what's wrong. 我认为这是由于keyhash等,但我不明白这一点,以找出错误。 What I do is, I click export, application, then I create a new keystore (the first time, otherwise I use existing keystore), then I find my hashkey using "keytool exportcert" etc as show on the fbook dev site. 我做的是,我点击导出,应用程序,然后我创建一个新的密钥库(第一次,否则我使用现有的密钥库),然后我发现我的哈希键使用“keytool exportcert”等在fbook开发站点上显示。 Then I enter that hashkey into the app on my facebook account. 然后我在我的Facebook帐户中输入该哈希键到应用程序中。 But sometimes even though the keystore password is correct it says "keystore format" is different, even though I used it before the same app! 但有时即使密钥库密码是正确的,它说“密钥库格式”也不同,即使我在同一个应用程序之前使用它! Then I have to create a new keystore, and exportcert again and all of that is a pain! 然后我必须创建一个新的密钥库,再次exportcert,这一切都很痛苦! There must be an easier way? 必须有一个更简单的方法吗?

Can someone possibly explain how the hashkey for Facebook apps work as well? 有人可以解释Facebook应用程序的哈希键是如何工作的吗?

Thanks in advance! 提前致谢!

My Authentication Code : 我的验证码:

public void login()
{

    facebook.authorize(this,new String[] { "email", "read_stream", "publish_stream"}, new DialogListener(){
        int fbcheck=0;
        @Override
        public void onComplete(Bundle values) {
            fbcheck=1;
        facebookauthcheck(fbcheck);
        }

        @Override
        public void onFacebookError(FacebookError error) {
            fbcheck=0;
            facebookauthcheck(fbcheck);
        }

        @Override
        public void onError(DialogError e) {
        fbcheck=0;
        facebookauthcheck(fbcheck);
        }

        @Override
        public void onCancel() {
            fbcheck=2;
            facebookauthcheck(fbcheck);
            }

    });
}

public void facebookauthcheck(int fbcheck)
{
    if (fbcheck == 0)   {
        Toast.makeText(this, "Authentication Error", Toast.LENGTH_LONG).show();
    }
    else if (fbcheck==1)
    {
        Toast.makeText(this, "Authenticated", Toast.LENGTH_LONG).show();
    }
    else
        Toast.makeText(this, "Authentication Cancelled", Toast.LENGTH_LONG).show(); 
}

Yeah I had this issue, 是的,我有这个问题,

It worked fine on the emulator, worked fine on my dev phone, but failed on the test users phone. 它在模拟器上运行良好,在我的开发电话上工作正常,但在测试用户手机上失败了。

It's to do with the Facebook app and SSO. 这与Facebook应用程序和SSO有关。

Have a read of this : http://sean.lyn.ch/2011/07/android-the-facebook-sdk-sso-and-you/ 请阅读: http//sean.lyn.ch/2011/07/android-the-facebook-sdk-sso-and-you/

It has 3 solutions. 它有3个解决方案。

I couldn't get SSO to work so I went for option two, (opt out of SSO!) This is done by: 我无法让SSO工作所以我选择了第二个选项,(选择退出SSO!)这是通过以下方式完成的:

  facebook.authorize(this, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH, this);

If you want to fix it and get SSO to work: 如果你想修复它并让SSO工作:

Correctly generate your hash key for the debug apk certificate. 正确生成调试apk证书的哈希键。 (detailed in the link above). (详见上面的链接)。

Ref: 参考:

Corresponding SO Question 相应的SO问题

I am using facebook login with fragments (please replace 'activity') with 'this': 我使用facebook登录片段(请用'this'代替'activity'):

 private void loginToFacebook()
    {
        mPrefs = activity.getPreferences(Context.MODE_PRIVATE);
        facebook = new Facebook(APP_ID);
        accessToken = mPrefs.getString("access_token", null);
        long expires = mPrefs.getLong("access_expires", 0);

        if (accessToken != null)
        {
            facebook.setAccessToken(accessToken);
        }

        if (expires != 0)
        {
            facebook.setAccessExpires(expires);
        }

        if (!facebook.isSessionValid())
        {
            facebook.authorize(activity, new String[] {"publish_stream"}, Facebook.FORCE_DIALOG_AUTH, new DialogListener() {

                public void onFacebookError(FacebookError arg0) {
                    // TODO Auto-generated method stub

                }

                public void onError(DialogError arg0) {
                    // TODO Auto-generated method stub

                }

                public void onComplete(Bundle arg0) {
                      SharedPreferences.Editor editor = mPrefs.edit();
                        editor.putString("access_token", facebook.getAccessToken());
                        editor.putLong("access_expires", facebook.getAccessExpires());
                        editor.commit();                        
                        uploadPhoto(facebook, bitmap, null); // calling another method to upload an image to FB after logging in..              
                }

                public void onCancel() {
                    // TODO Auto-generated method stub

                }
            });

        }
    }

暂无
暂无

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

相关问题 facebook 在模拟器上工作,而不是在设备上 - facebook working on emulator not on device Facebook集成可以在模拟器中运行,但不能在Android设备中运行吗? - Facebook integration working in emulator but not working in android device? react-native helow world 应用程序 - 在模拟器中工作但不在物理设备中 - react-native hellow world app - working in emulator but not in physical device Facebook图像共享可在模拟器中运行,但不能在设备中运行 - Facebook image sharing working in emulator but not in device 在模拟器上调用了onPerformSync,但没有在物理设备上调用 - onPerformSync called on emulator but not physical device AlarmManager在仿真器中触发,但不在物理设备上触发 - AlarmManager firing in emulator but not on physical device 在任何物理设备或模拟器中以调试模式在模拟器中工作时,Google 登录无法在生产应用程序中工作 - Google Sign in not working in Production app while working in emulators in debug mode in any device physical or emulator Flutter 电话身份验证在模拟器上工作正常,但在真实设备上不工作(Android) - Flutter Phone authentication works fine on emulator but not working on real device (Android) Facebook无法在Android设备上登录,但可以在Android Studio模拟器中使用 - Facebook log in on Android device not working, but works in Android Studio Emulator .2秒延迟,单击物理设备上的按钮,但不单击仿真器 - .2 second delay clicking Button on physical device but not emulator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM