0

I have been following this guide: http://developers.facebook.com/docs/guides/mobile/#android

Now I generate the key with

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore 
| openssl sha1 -binary
| openssl base64

as instructed, and I add this key to my Facebook app and to pass it in my code:

public class FacebookSyncActivity extends Activity{
    Facebook facebook = new Facebook("THE KEY");

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.facebook_layout);

        facebook.authorize(this, new DialogListener() {
            @Override
            public void onComplete(Bundle values) {}

            @Override
            public void onFacebookError(FacebookError error) {}

            @Override
            public void onError(DialogError e) {}

            @Override
            public void onCancel() {}
        });
    }

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

        facebook.authorizeCallback(requestCode, resultCode, data);
    }

but each time I try to login on my device or the simulator I get this error message:

An Error occurred. Please try again later

It looks to be an issue for many people as can be seen on their github page https://github.com/facebook/facebook-android-sdk/issues/74

What do you think?

Alex1987
  • 9,169
  • 14
  • 68
  • 90
  • Have you checked the logcat? I occasionally have a similiar issue where the login screen just stays blank, but that throws a SSL error into the log. And have you also tried this both with and without the FB app installed? (Its in the SDK folder, use "adb install Facebook.apk" to install it) Maybe you can track the issue further down. If it works with one of them, you at least know that there is no issue with the keys/ids (maybe left a char while copying them over?). –  Jun 28 '11 at 19:55
  • Yes I did check the logcat but I don't see any errors. When I uninstall facebook I also get a dialog (a different one - smaller, which probably is not the "native" facebook dialog, but rather something of the SDK for facebook), with the same error. And then when I press "oKay" it launches the browser with facebook. There is no way I left a char over - I have done this a 100 times already and each time I get this stupid error :( – Alex1987 Jun 29 '11 at 12:26

2 Answers2

1

Have you tried getting the Hash key this way, SEt your project build Target to 2.0 (sdk5):

try {
        info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md;

                md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                String something = new String(Base64.encode(md.digest(), 0));
                Log.e("hash key", something);
        } 
    } catch (NameNotFoundException e1) {            
        Log.e("name not found", e1.toString());
    } catch (NoSuchAlgorithmException e) {
             Log.e("no such an algorithm", e.toString());
     }catch (Exception e){
             Log.e("exception", e.toString());
     }

Got this because I just asked a similar question!

Community
  • 1
  • 1
Blundell
  • 73,122
  • 30
  • 204
  • 230
  • Yes I did try that (I set the target to 2.1, not 2.0), but it gives EXACTLY the same key I got with the keygen! BTW the link you gave is talking about a different issue... – Alex1987 Jun 29 '11 at 12:19
  • Yeah I said similar not the same :-) . Interesting that it gives the exact same and that it doesn't work. Perhaps it's not your key then – Blundell Jun 29 '11 at 15:21
1

Ok after many hours of banging my head against the wall I found the problem :) It seems that I mistakenly pass the Key that I generated to the facebook constructor - When I simply needed to put the Application Key from the app page on facebook. I think that this caused a confusion with many people...

Alex1987
  • 9,169
  • 14
  • 68
  • 90
  • Damn, as you mentioned it. Yeah I did that the first time too. Sorry I didn't remember that one. =/ Sadly, Facebooks documentation is not always clear. –  Jun 29 '11 at 14:24