Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm trying to integrate facebook into my app and so have followed the tutorial at: Facebook Android but I can't get the first example (Single Sign-On) to work. When my app loads up I get the facebook dialog but it just says "An error occurred. Please try again later." with a facebook-style "Ok" button at the bottom and there is nothing in logcat: App showing Facebook error

I followed the steps in the tutorial but I'm guessing there is something wrong with the APP ID or the hashkey generated by keytool. Here are the steps I followed:

  1. clone fb git.
  2. create fbSDK project.
  3. create own fb project and link the fbSDK as a library.
  4. I then did the keytool cmd with openssl and input the password "android" as suggested by others on stackoverflow.
  5. I went to developers.facebook.com and created a new app.
  6. In "Edit Settings->Mobile and Devices" I put my hash in the box provided.
  7. In "Edit Settings->Mobile and Devices" I chose "Native App" as "Application Type"
  8. Back in the app I copy and pasted the SSO example code.
  9. I changed the "YOUR_APP_ID" in the Facebook() constructor to the APP ID shown on the developers.facebokk.com page for my new app.
  10. I ran the app on my phone.

I don't know why there is nothing in logcat but when I install it, the Console always, without fail, says the:ActivityManager: Warning: Activity not started, its current task has been brought to the front

And I can't find any logcat reference to my app or the error I was getting from the facebook sdk which was: Facebook-ProxyAuth(4828): Failed to read calling package's signature.

I have been at this for a few hours now and any help would be greatly appreciated. I can't believe the facebook SDK and help is so sketchy for Android, facebook should be ashamed of themselves.

Thanks,

InfinitiFizz

like image 748
Infiniti Fizz Avatar asked Mar 06 '11 17:03

Infiniti Fizz


3 Answers

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!".)

like image 161
FYI-FacebookAPIIsBuggy Avatar answered Oct 13 '22 06:10

FYI-FacebookAPIIsBuggy


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).
like image 32
Anas Avatar answered Oct 13 '22 07:10

Anas


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.

like image 35
dell116 Avatar answered Oct 13 '22 08:10

dell116