Do I Need Hash Keys To Build Use Facebook Api In My App

I want my app to get access to user profile and post a photo on her/his timeline. If I am doing this for android then am I requiring any hash key ? As when I build this code with a APP ID, I started getting good results, every thing fine but when I try to login any other profile, an error comes that say that “android_key _not_configured : The android key hash for this application is not configured.”

Here I am unable to get the fact that application works fine when I use my personal developer profile but fails and generates this error for other profiles. If I need a hash key then why this working fine for one case? 

[lua]

 

local facebook = require “facebook”

local widget = require"widget"

 

local fbAppID = “my key”  – my own generated key

 

local sessionComplete = function(event)

–removing the already existed image

if imageCaptured ~= nil then

imageCaptured.isVisible=false

end

imageCaptured = event.target

print( "Camera ", ( imageCaptured and “returned an image” ) or “session was cancelled” )

print( "event name: " … event.name )

print( "target: " … tostring( imageCaptured ) )

if imageCaptured then

imageCaptured:setReferencePoint( display.TopRightReferencePoint )

imageCaptured.width = display.contentWidth*0.5

imageCaptured.height = display.contentHeight*0.3

 --displaying in the center

imageCaptured.xOrigin = display.contentWidth*0.75;imageCaptured.yOrigin = display.contentHeight*0.2

myimagename = “myimage.jpg”

local baseDir = system.DocumentsDirectory

 display.save(imageCaptured , myimagename,baseDir )

end

end

–call when camera button is pressed

local function onCapturePress(event)

–text = “REPLACE PICTURE”

–print(“picture will only be taken when recording is on”)

if  media.hasSource( media.Camera ) then

media.show( media.Camera, sessionComplete )

–print(“starting camera”)

else

native.showAlert(“Corona”, “Camera not found.”)

end

end

local function onLoginSuccess()

– Upload ‘iheartcorona.jpg’ to current user’s account

local attachment = {

message = “I want this to be printed on my facebook timeline.”,

source = { baseDir=system.DocumentsDirectory, filename=“myimage.jpg”, type=“image” }

}

facebook.request( “me/photos”, “POST”, attachment )

end

– facebook listener

function fbListener( event )

if event.isError then

native.showAlert( “ERROR”, event.response, { “OK” } )

else

if event.type == “session” and event.phase == “login” then

– login was a success; call function

onLoginSuccess()

elseif event.type == “request” then

– this block is executed upon successful facebook.request() call

native.showAlert( “Success”, “Your image has been posted.”, { “OK” } )

end

end

end

local function onSendPress(event)

– photo uploading requires the “publish_stream” permission

facebook.login( fbAppID, fbListener, { “publish_stream” } )

end

capture = widget.newButton{

style = “blackLarge”,

label = “CAPTURE” ,

 onPress = onCapturePress

 }

capture.x = display.contentWidth-(display.contentWidth*0.8)

capture.y = display.contentHeight-(display.contentHeight*0.1)

 send = widget.newButton{

 style = “blackLarge”,

 label = “SEND” ,

 onPress = onSendPress

 }

send.x = display.contentWidth-(display.contentWidth*0.3)

send.y = display.contentHeight-(display.contentHeight*0.1)

[/lua]

 

I just using two buttons.

capture button is just capturing the image and send is posting to timeline.

You need to generate a hash key, and enter it in native android app settings on App settrings page, and in the developer profile. I had the same problem, when the other user couldn’t log in. The solution is to turn off sand box mode of app, or add testers in Developer Roles of your app. Also here https://developers.facebook.com/apps?view=app_requests the tester should accept, that he is a tester.

Yes you need to generate a hash key to connect to Facebook via Android and set it up on your app settings page.

This thread has some information you might find useful: http://developer.coronalabs.com/forum/2012/03/20/facebook-and-android-key-hash

If you want to generate your own hash key, then this is a useful tutorial as well (if you’re using a mac): http://base.techority.com/2013/01/01/how-to-generate-a-key-for-your-android-app-on-a-mac/ 

I have tried to generate the hash with this command:

keytool -exportcert -alias my_game -keystore d:\keystore\my_game | openssl sha1 -binary | openssl base64

but got this error:

’openssl’ is not recognized as an internal or external command,
operable program or batch file.

Where do I get openssl from ?

I am on Windows.

Regards,

Damir.

Not sure about windows, but a quick google search found this which might be of use:

http://stackoverflow.com/questions/7506392/how-to-create-android-facebook-key-hash

Thank you for your help but I can’t get this working and I think I have tried everything possible.

I managed to generate the hash key, used the same alias and keystore I used creating the app (I was prompted for the password).

The hash is a 28 long alphanumeric.

Entered it on the facebook app page along with the package name and the class name (com.ansca.corona.CoronaActivity).

After trying to login I get this screen:

facebook.png

In the application log there is no error with the right hash as described in another thread.

Here is the log:

06-28 22:24:30.070: I/ActivityManager(1160): Starting: Intent { cmp=com.facebook.katana/.ProxyAuth (has extras) } from pid 9923
06-28 22:24:30.070: D/PhoneWindow(9923): couldn’t save which view has focus because the focused view android.widget.FrameLayout@4055f6b8 has no id.
06-28 22:24:30.130: I/ActivityManager(1160): Starting: Intent { cmp=com.facebook.katana/.ProxyAuthDialog (has extras) } from pid 3479
06-28 22:24:30.180: I/Corona(9923): applicationSuspend
06-28 22:24:30.190: D/FlurryAgent(9923): Ending session
06-28 22:24:30.520: E/SkLayout_wtle(3479): layout error:106 width:0 ellipsizedWidth:0
06-28 22:24:30.580: W/AudioFlinger(1081): write blocked for 46 msecs, 849 delayed writes, thread 0xc998
06-28 22:24:30.780: I/ActivityManager(1160): Displayed com.facebook.katana/.ProxyAuthDialog: +640ms (total +666ms)
06-28 22:24:31.090: D/dalvikvm(3479): GC_CONCURRENT freed 1925K, 36% free 11128K/17159K, external 2908K/3123K, paused 6ms+10ms
06-28 22:24:31.540: W/IdleConnectionHandler(3479): Removing a connection that never existed!
06-28 22:24:32.210: I/CustomizationProvider(9731): No configuration file: /system/etc/customization/settings/com/sonyericsson/textinput/uxp/custom_settings.xml
06-28 22:24:33.240: I/AudioHardwareQSD(1081): AudioHardware pcm playback is going to standby.
06-28 22:24:40.210: D/FlurryAgent(9923): Sending report to: http://data.flurry.com/aar.do
06-28 22:24:41.000: D/FlurryAgent(9923): Report successful
06-28 22:25:05.050: D/dalvikvm(1772): GC_EXPLICIT freed 12K, 53% free 2581K/5379K, external 1685K/2133K, paused 26ms

Don’t have a clue what else to try.

:frowning:

First, go to C:\program files\java\jre6\bin directory Download from this site http://www.openssl.org/ openssl and extrackt the archive to the same derictory where keytool is. Then execute this command

keytool -exportcert -alias my_game -keystore d:\keystore\my_game | openssl sha1 -binary | openssl base64

@petrov

Why this ? “First, go to C:\program files\java\jre6\bin directory

I have already downloaded openssl (from another location) and executed the command you suggested.

It asked for a keystore password and I got the generated 28 alphanumeric hash which I entered in facebook app page.

So I guess this is not the problem.

You need to generate a hash key, and enter it in native android app settings on App settrings page, and in the developer profile. I had the same problem, when the other user couldn’t log in. The solution is to turn off sand box mode of app, or add testers in Developer Roles of your app. Also here https://developers.facebook.com/apps?view=app_requests the tester should accept, that he is a tester.

Yes you need to generate a hash key to connect to Facebook via Android and set it up on your app settings page.

This thread has some information you might find useful: http://developer.coronalabs.com/forum/2012/03/20/facebook-and-android-key-hash

If you want to generate your own hash key, then this is a useful tutorial as well (if you’re using a mac): http://base.techority.com/2013/01/01/how-to-generate-a-key-for-your-android-app-on-a-mac/ 

I have tried to generate the hash with this command:

keytool -exportcert -alias my_game -keystore d:\keystore\my_game | openssl sha1 -binary | openssl base64

but got this error:

’openssl’ is not recognized as an internal or external command,
operable program or batch file.

Where do I get openssl from ?

I am on Windows.

Regards,

Damir.

Not sure about windows, but a quick google search found this which might be of use:

http://stackoverflow.com/questions/7506392/how-to-create-android-facebook-key-hash

Thank you for your help but I can’t get this working and I think I have tried everything possible.

I managed to generate the hash key, used the same alias and keystore I used creating the app (I was prompted for the password).

The hash is a 28 long alphanumeric.

Entered it on the facebook app page along with the package name and the class name (com.ansca.corona.CoronaActivity).

After trying to login I get this screen:

facebook.png

In the application log there is no error with the right hash as described in another thread.

Here is the log:

06-28 22:24:30.070: I/ActivityManager(1160): Starting: Intent { cmp=com.facebook.katana/.ProxyAuth (has extras) } from pid 9923
06-28 22:24:30.070: D/PhoneWindow(9923): couldn’t save which view has focus because the focused view android.widget.FrameLayout@4055f6b8 has no id.
06-28 22:24:30.130: I/ActivityManager(1160): Starting: Intent { cmp=com.facebook.katana/.ProxyAuthDialog (has extras) } from pid 3479
06-28 22:24:30.180: I/Corona(9923): applicationSuspend
06-28 22:24:30.190: D/FlurryAgent(9923): Ending session
06-28 22:24:30.520: E/SkLayout_wtle(3479): layout error:106 width:0 ellipsizedWidth:0
06-28 22:24:30.580: W/AudioFlinger(1081): write blocked for 46 msecs, 849 delayed writes, thread 0xc998
06-28 22:24:30.780: I/ActivityManager(1160): Displayed com.facebook.katana/.ProxyAuthDialog: +640ms (total +666ms)
06-28 22:24:31.090: D/dalvikvm(3479): GC_CONCURRENT freed 1925K, 36% free 11128K/17159K, external 2908K/3123K, paused 6ms+10ms
06-28 22:24:31.540: W/IdleConnectionHandler(3479): Removing a connection that never existed!
06-28 22:24:32.210: I/CustomizationProvider(9731): No configuration file: /system/etc/customization/settings/com/sonyericsson/textinput/uxp/custom_settings.xml
06-28 22:24:33.240: I/AudioHardwareQSD(1081): AudioHardware pcm playback is going to standby.
06-28 22:24:40.210: D/FlurryAgent(9923): Sending report to: http://data.flurry.com/aar.do
06-28 22:24:41.000: D/FlurryAgent(9923): Report successful
06-28 22:25:05.050: D/dalvikvm(1772): GC_EXPLICIT freed 12K, 53% free 2581K/5379K, external 1685K/2133K, paused 26ms

Don’t have a clue what else to try.

:frowning:

First, go to C:\program files\java\jre6\bin directory Download from this site http://www.openssl.org/ openssl and extrackt the archive to the same derictory where keytool is. Then execute this command

keytool -exportcert -alias my_game -keystore d:\keystore\my_game | openssl sha1 -binary | openssl base64

@petrov

Why this ? “First, go to C:\program files\java\jre6\bin directory

I have already downloaded openssl (from another location) and executed the command you suggested.

It asked for a keystore password and I got the generated 28 alphanumeric hash which I entered in facebook app page.

So I guess this is not the problem.