Facebook SSO example not working - “An error ocurred. Please try again later”

守給你的承諾、 提交于 2019-12-03 15:01:48

You have to call .request() from a separate thread. If you do it on the UI thread the facebook authorize doesn't complete before your code executes. So call the new thread in the "onComplete" of facebook authorization. You'll have a valid access token at this point. Good luck!

(this is why the api says "don't call this from the UI thread!".)

In fact I have encountered the same problem exactly and it solved. So, in the hash key generation use the following steps:

  1. open cmd and go to your android SDK path.
  2. type this command : keytool -exportcert -alias androiddebugkey -keystore [your SDK path | e.g c:\users\user].android\debug.keystore | openssl sha1 -binary | openssl base64
  3. after that it's promet for password enter "android"
  4. copy the result to your facebook app settings and save settings.
  5. in your android app use the facebook app id(not the android hash key).

I had this problem simply because I was making calls to the facebook api before I properly initialized the facebook object with the correct key. Just make sure you're using the right key and you're initializing the Facebook object properly.

Also, I've also been tripped up a few times by attempting to make facebook api calls with a different android application key. Keep in mind that the facebook tutorial instructs you to create your key with a compiled apk. This key hash will be different if you're going to run your code from the IDE (i'm using Eclipse). When you run your app directly from eclipse the facebook key will be different because when running your app from eclipse it's using a default release key to build your app.

Because of this I usually have two keys in the facebook developer portal. One key that was created with an apk compiled with the release-key used for the Android market and another key that was created from running the app code directly from eclipse.

Any reason you selected Native App in step 7? I left it at the default HTML5 / mobile web and got the sample to work.

The best way to correctly find out your hash is this lil piece of code.:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "com.facebook.samples.loginhowto", 
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }
    ...

Replace com.facebook.samples.loginhowto with your own package name.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!