Ah, I am trying to do this from my Windows PC. I will give it a try on my MAC.
Windows is a different command…
See this stack overflow page:
http://stackoverflow.com/questions/7506392/how-to-create-android-facebook-key-hash
you likely will need to install OpenSSL for Windows.
Thanks Rob!
That really helped me. My app is working fine now … and i know why
@Rob Miracle
You’re right on how the login happens. But here’s what’s the problem in both cases:
Case 1. When it uses the webView, you can ask whatever permissions you want to, because it behaves like authentication on a browser. It works even with a wrong hashkey.
Case 2. When using the native Facebook app, since versio 3.0.1 of the Android sdk you can’t ask for reading and writing permissions at the same time. You can do that with the web authentication, and that’s why case 1 works. But with the native sdk Facebook won’t handle the permissions and ask user about each one.
That’s why this code :
local function getPermissions(event) if(event.type == "session") then facebook.logout() facebook.login( fbAppID, fbListener, {"publish\_stream"}) end end facebook.login( fbAppID, getPermissions)
Works in Case 2, and Case 1 (but the user has to enter his login details twice)
And that’s why this code only works in Case 1:
--without asking reading/basic permissions prior facebook.login( fbAppID, fbListener, {"publish\_stream"})
Hope this makes everything clear on what’s happening here.
Quick question about generating the hash. Do I need to have my keystore file available for the command line to use when generating the hash? Or is the hash just generated from whatever the name of my keystore is that I enter? Does the hash thats created have to be entered anywhere else besides the facebook developer apps page?
keytool -exportcert -alias YOUR_APP_ALIAS -keystore YOUR_KEYSTORE.keystore
That command READS your existing keystore and exports the certificate from it. The | character is called a pipe, it redirects the output from keytool to openssl where it encrypts the certificate using the SHA1 method and outputs a binary version. It’s then piped back through openssl a 2nd time to create a Base64 encoded version of the SHA1 hash.
Short answer is yes, it has to be able to read the keystore your app is compiled against. This is why you have to change YOUR_APP_ALIAS and YOUR_KEYSTORE to the right names, why the password has to be the same one you built the keystore with in the first place.
Also in that form of the command, it’s specifically looking for the keystore in the current folder. In the window’s example I linked to above, they used a full path to the keystore. If you are not in the right folder, you have to include the right path to find it.
@Rob,
Thanks thats what I was wondering. How does it know where the key store file is?! That makes sense to have it in the same folder. I’ll give that a try.
You have to know where you saved it. On Mac’s most instructions tell you to store it in a folder named “android” off of your home directory. On Windows I would have no idea where it put it. You can use your Start button and put the name of your keystore in the search box and help locate it that way.
Hi rob
We are facing issue with the Facebook post photo in android . I was able to post the message if there is no facebook app on the android phone .If there is a Facebook app the post photo is not at all working for android. Whats the issue with the Facebook app.Any one else facing the same issue .Please post .
Please reply us and tell us the solution for this .
@info8888 have you built and tested the sample app?
Are you getting any errors in your console log (use: adb logcat to view…)
Have you gone through the facebook setup guide: http://docs.coronalabs.com/guide/social/setupFacebook/index.html
Does your keystore match what Facebook is watching (will have an error in your console log)
Hi rob
Here we are giving the log messages but if keystore or app id is wrong it should not work with the normal browser of facebook but with that its getting posted.(Its not working only when the facebook app is there in the android mobile).Here is the log.
07-13 07:24:00.559: W/fb4a(:<default>):BlueServiceQueue(23345): Exception during service
07-13 07:24:00.559: W/fb4a(:<default>):BlueServiceQueue(23345): com.facebook.http.protocol.ApiException: remote_app_id does not match stored id
07-13 07:24:00.559: W/fb4a(:<default>):BlueServiceQueue(23345): at com.facebook.http.protocol.ApiResponseChecker.b(ApiResponseChecker.java:78)
07-13 07:24:00.559: W/fb4a(:<default>):BlueServiceQueue(23345): at com.facebook.http.protocol.ApiResponseChecker.a(ApiResponseChecker.java:107)
07-13 07:24:00.559: W/fb4a(:<default>):BlueServiceQueue(23345): at com.facebook.http.protocol.ApiResponse.h(ApiResponse.java:291)
07-13 07:24:00.559: W/fb4a(:<default>):BlueServiceQueue(23345): at com.facebook.katana.server.protocol.AuthorizeAppMethod.a(AuthorizeAppMethod.java:266)
07-13 07:24:00.559: W/fb4a(:<default>):BlueServiceQueue(23345): at com.facebook.katana.server.protocol.AuthorizeAppMethod.a(AuthorizeAppMethod.java:27)
07-13 07:24:00.559: W/fb4a(:<default>):BlueServiceQueue(23345): at com.facebook.http.protocol.SingleMethodRunnerImpl.a(SingleMethodRunnerImpl.java:157)
07-13 07:24:00.559: W/fb4a(:<default>):BlueServiceQueue(23345): at com.facebook.http.protocol.AbstractSingleMethodRunner.a(AbstractSingleMethodRunner.java:16)
07-13 07:24:00.559: W/fb4a(:<default>):BlueServiceQueue(23345): at com.facebook.katana.server.handler.PlatformOperationHandler.c(PlatformOperationHandler.java:366)
07-13 07:24:00.559: W/fb4a(:<default>):BlueServiceQueue(23345): at com.facebook.katana.server.handler.PlatformOperationHandler.a(PlatformOperationHandler.java:259)
07-13 07:24:00.559: W/fb4a(:<default>):BlueServiceQueue(23345): at com.facebook.fbservice.service.BlueServiceQueue.d(BlueServiceQueue.java:245)
07-13 07:24:00.559: W/fb4a(:<default>):BlueServiceQueue(23345): at com.facebook.fbservice.service.BlueServiceQueue.d(BlueServiceQueue.java:51)
07-13 07:24:00.559: W/fb4a(:<default>):BlueServiceQueue(23345): at com.facebook.fbservice.service.BlueServiceQueue$3.run(BlueServiceQueue.java:191)
07-13 07:24:00.559: W/fb4a(:<default>):BlueServiceQueue(23345): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:444)
07-13 07:24:00.559: W/fb4a(:<default>):BlueServiceQueue(23345): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
07-13 07:24:00.559: W/fb4a(:<default>):BlueServiceQueue(23345): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
07-13 07:24:00.559: W/fb4a(:<default>):BlueServiceQueue(23345): at com.facebook.common.executors.HandlerExecutorServiceImpl$ListenableScheduledFuture.run(HandlerExecutorServiceImpl.java:268)
07-13 07:24:00.559: W/fb4a(:<default>):BlueServiceQueue(23345): at android.os.Handler.handleCallback(Handler.java:587)
07-13 07:24:00.559: W/fb4a(:<default>):BlueServiceQueue(23345): at android.os.Handler.dispatchMessage(Handler.java:92)
07-13 07:24:00.559: W/fb4a(:<default>):BlueServiceQueue(23345): at android.os.Looper.loop(Looper.java:130)
07-13 07:24:00.559: W/fb4a(:<default>):BlueServiceQueue(23345): at android.os.HandlerThread.run(HandlerThread.java:60)
07-13 07:24:00.569: W/fb4a(:<default>):GDPDialog(23345): Failed to send
07-13 07:24:00.569: W/fb4a(:<default>):GDPDialog(23345): com.facebook.fbservice.service.ServiceException: API_ERROR: API_ERROR
07-13 07:24:00.569: W/fb4a(:<default>):GDPDialog(23345): at com.facebook.fbservice.ops.BlueServiceOperation.c(BlueServiceOperation.java:637)
07-13 07:24:00.569: W/fb4a(:<default>):GDPDialog(23345): at com.facebook.fbservice.ops.BlueServiceOperation.c(BlueServiceOperation.java:46)
07-13 07:24:00.569: W/fb4a(:<default>):GDPDialog(23345): at com.facebook.fbservice.ops.BlueServiceOperation$2.run(BlueServiceOperation.java:602)
07-13 07:24:00.569: W/fb4a(:<default>):GDPDialog(23345): at android.os.Handler.handleCallback(Handler.java:587)
07-13 07:24:00.569: W/fb4a(:<default>):GDPDialog(23345): at android.os.Handler.dispatchMessage(Handler.java:92)
07-13 07:24:00.569: W/fb4a(:<default>):GDPDialog(23345): at android.os.Looper.loop(Looper.java:130)
07-13 07:24:00.569: W/fb4a(:<default>):GDPDialog(23345): at android.app.ActivityThread.main(ActivityThread.java:3687)
07-13 07:24:00.569: W/fb4a(:<default>):GDPDialog(23345): at java.lang.reflect.Method.invokeNative(Native Method)
07-13 07:24:00.569: W/fb4a(:<default>):GDPDialog(23345): at java.lang.reflect.Method.invoke(Method.java:507)
07-13 07:24:00.569: W/fb4a(:<default>):GDPDialog(23345): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
07-13 07:24:00.569: W/fb4a(:<default>):GDPDialog(23345): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
07-13 07:24:00.569: W/fb4a(:<default>):GDPDialog(23345): at dalvik.system.NativeStart.main(Native Method)
This seems like a place I would check: remote_app_id does not match stored id
You pass an AppID to the facebook.init() call and that needs to match what you have setup on the Facebook Developer portal. I would start by making sure you have all of those values correct.
Facebook’s setup is overly complex in my opinion and they change things way too often. In fact about once a quarter they “break” things seemingly on purpose.
Same issue with latests builds
Corona should provide us access to request additional permission to facebook (see latest facebook breaking changes and related documentation)
The tutorial is outdated. I get the same errors posted above (both of them). From what I searched over the internet they are actually because of the invalid hash key.
I tried to find the problem and I posted what I found in this other thread (http://forums.coronalabs.com/topic/37173-facebook-key-hashes-no-longer-required-for-android/)
Any ideas?
A quick note to let you know that I checked to see if my FB integration broke with the daily build 1158, and I’ve verified it is working fine with mine.
I wonder what might be causing this issue…
Naomi
Not sure if this is how we should officially use fb from now on, but I found a fix for it:
http://forums.coronalabs.com/topic/37173-facebook-key-hashes-no-longer-required-for-android/
Thanks for replying. The values i am passing are correct and i am confident about it because if i remove the facebook app from mobile its getting posted . If we fbapp then only its not working .Please solve the issue i tried to fix what beckslash had told us but still the same issue . Even if we keep 123 in our keyhash field of fb developer account its not giving the exact keyshash in the log .
Thanks
@info8888 You won’t be able to see the hash key into the logs. You have to generate that yourself from the console.
But even if you have it right you first need to authenticate the user for reading permissions, then for writing. You can no longer do it with only one call.
When you don’t have FB app installed, the configuration from facebook portal doesn’t matter at all. So that’s not a sign that you have the right hash.
Did you use this code?
keytool -exportcert -alias YOUR_APP_ALIAS -keystore YOUR_KEYSTORE.keystore | openssl sha1 -binary | openssl base64
And enter your password for the keystore and not “android”.
If you’re developing on windows make sure you have the right (latest I think) openssl version. Different versions give you different outputs.