Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Creating Facebook app for Android - quesiton
Started by WarrenW Oct 31 2012 10:18 AM

- - - - -
72 replies to this topic
[TOPIC CONTROLS]
Page 1 of 3 1 2 3
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

WarrenW

[GLOBAL: userInfoPane.html]
WarrenW
  • Contributor

  • 830 posts
  • Corona SDK

Hi,

I want to build an android app with corona sdk to login and post photos to Facebook. When creating an app on the Facebook developers page do I select Native Android App? If so what about the Class Name and Key Hashes? What do I do for that? I just need to know how to set it up on the Facebook side. I've read many pages on here but still need some help.

Thanks!

Warren
uid: 184193 topic_id: 32551 reply_id: 332551


[TOPIC: post.html]
#2

Omnigeek Media

[GLOBAL: userInfoPane.html]
Omnigeek Media
  • Corona Geek

  • 2,975 posts
  • Corona SDK

Yes, you create a class name. It's the same as your app's package name (i.e. com.yourcompany.yourapp)

As for the keyhash, go google keyhash and facebook. I don't remember the syntax, but basically you run a command line tool to generate the keyhash. It will most likely be the wrong keyhash, but put it in anyway and try to login with your app. In the console log, facebook will tell you the keyhash it's looking for, copy that keyhash and add it to your android settings and you are good to go.
uid: 19626 topic_id: 32551 reply_id: 129467


[TOPIC: post.html]
#3

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Have a look at the following blog posts. They explain how to set up your facebook developer page, how to retrieve the hash key for your app, and how to upload a photo.

http://www.coronalabs.com/blog/2012/07/25/faq-wednesday-your-facebook-questions/
http://www.coronalabs.com/blog/2011/12/16/uploading-photos-to-facebook-in-corona/
uid: 32256 topic_id: 32551 reply_id: 129483


[TOPIC: post.html]
#4

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Contributor

  • 751 posts
  • Corona SDK

@joshua,
I am also in the middle of trying to make this work and had a question. Should we have to create our app in the facebook App center before our app and facebook can interact? I currently have entered all the required info on facebooks end such as the android hash, and all that info, but when I run my app and try to login I get "my app is misconfigured for Facebook login. Press Okay to go back to the application without connecting it to Facebook.

As a side note for the class name I have entered in "com.ansca.corona.CoronaActivity", but according to robMiracle's post above, should I instead be using my package name?

thanks
uid: 19620 topic_id: 32551 reply_id: 129485


[TOPIC: post.html]
#5

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

rxmarccall,

You should create your app first and decide what the final package name is going to be. Then set up your facebook developer page.

You set "Android Package Name" to your app's unique package name.

You set "Class Name" to "com.ansca.corona.CoronaActivity". This is used to launch your app from facebook.

For the hash key, follow the FAQ that I posted a link to up above. The simplest solution is to attempt to log into facebook from your app with a "bad" hash key. It will fail, as expected, but the Android log will print the hash key that facebook was expecting. Copy and paste that hash key to your facebook developer page.

That FAQ also provides information that is relevant to both iOS and Android, such as how to set up your app to receive a token with an expiration of 60 days instead of the default few hour expiration.
uid: 32256 topic_id: 32551 reply_id: 129490


[TOPIC: post.html]
#6

WarrenW

[GLOBAL: userInfoPane.html]
WarrenW
  • Contributor

  • 830 posts
  • Corona SDK

Hi, I was able to get the login dialog to popup on my app. So i got that far. Now I need to see how to upload a photo. I saw the code for it but I can't figure out how to specify the folder on my android. Like what the baseDir would be for the Download folder or the camera pictures. Anyone know this?

After the login takes place I get a black screen. But I don't have any other code anyways so that must be what happens huh?
uid: 184193 topic_id: 32551 reply_id: 129511


[TOPIC: post.html]
#7

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Please see the "Constants" section from the below API documentation. Those constant specify which directory you want to access.
http://docs.coronalabs.com/api/library/system/index.html
uid: 32256 topic_id: 32551 reply_id: 129554


[TOPIC: post.html]
#8

Omnigeek Media

[GLOBAL: userInfoPane.html]
Omnigeek Media
  • Corona Geek

  • 2,975 posts
  • Corona SDK

Thanks for this Joshua. I had no clue what to put there and I put my app's package name in there and everything seems to work. If I use "com.ansca.corona.CoronaActivity" will that cause problems with multiple apps?

uid: 19626 topic_id: 32551 reply_id: 129564


[TOPIC: post.html]
#9

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

>> If I use "com.ansca.corona.CoronaActivity" will that cause problems with multiple apps?

No, because the "package name" you provide uniquely identifies your app.

The Android intent used to launch your app requires both a package name and the class type of the component to launch in its constructor, as documented here...
http://developer.android.com/reference/android/content/Intent.html#Intent(android.content.Context,%20java.lang.Class)

And by the way, as of this week's daily builds, Corona now supports launch arguments and the "applicationOpen" system events on Android. These features allow your app to support facebook deep linking.
uid: 32256 topic_id: 32551 reply_id: 129570


[TOPIC: post.html]
#10

Omnigeek Media

[GLOBAL: userInfoPane.html]
Omnigeek Media
  • Corona Geek

  • 2,975 posts
  • Corona SDK

What is "facebook deep linking"?
uid: 19626 topic_id: 32551 reply_id: 129577


[TOPIC: post.html]
#11

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Here is facebook's official documentation on deep linking...
http://developers.facebook.com/docs/mobile/android/deep_linking/

So, when the user taps on your app's link in facebook, it will launch your app and pass the URL that the user tapped on as an argument. You can customize the URL with parameters to tell your app to display a particular screen or perform a particular operation.
uid: 32256 topic_id: 32551 reply_id: 129594


[TOPIC: post.html]
#12

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Contributor

  • 751 posts
  • Corona SDK

@Joshua,

I don't know what else to do, I still get the "App Name is misconfigured for Facebook login". In the facebook Developers do I need to actually publish my app so that its live on facebook?

There is a "Submit App Details" button, which I have not done yet because my app is not 100% finished
uid: 19620 topic_id: 32551 reply_id: 129596


[TOPIC: post.html]
#13

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

I think you are setting up the wrong section on the facebook developer page.

You should be setting up your Android app in the "Settings\Basic" page. That's where you set up your mobile app and obtain an app ID. There is only a "Save Changes" button at the bottom of that page. I believe that should be enough.
uid: 32256 topic_id: 32551 reply_id: 129597


[TOPIC: post.html]
#14

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Contributor

  • 751 posts
  • Corona SDK

Does anyone know if your app needs to be active and published in the google play market to be able to test facebook integration? Maybe that is why I am getting this error?
uid: 19620 topic_id: 32551 reply_id: 129722


[TOPIC: post.html]
#15

Omnigeek Media

[GLOBAL: userInfoPane.html]
Omnigeek Media
  • Corona Geek

  • 2,975 posts
  • Corona SDK

No it does not. The app I'm building now is perfectly fine on Android with Facebook.

uid: 19626 topic_id: 32551 reply_id: 129728


[TOPIC: post.html]
#16

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Contributor

  • 751 posts
  • Corona SDK

I have a feeling my problem has to do with how I am trying to log into facebook. A lot of the guides talk about entering in a bad hash, running the app and looking at the log to see the correct hash. I believe I have the correct hash, and I have it entered on facebook. Does this same hash need to be put somewhere inside my actual app as well?

I am using the GGFacebook module found here: http://developer.coronalabs.com/code/ggfacebook

I am trying ot login to facebook just by doing
local appID = "***************" (real app ID there)facebook = GGFacebook:new( appID )facebook:login()


Does my hash need to be included in my GGFacebook:new call?

Here is what the documentation says from the above link:
"Create your Facebook object passing in your apps id, optional listener and permissions
local facebook = GGFacebook:new( appID, listener, permissions )"
uid: 19620 topic_id: 32551 reply_id: 129742


[TOPIC: post.html]
#17

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Contributor

  • 751 posts
  • Corona SDK

For anyone else having the same issue that I posted above, I got my issue resolved. I thought for sure I had the correct android hash key because I followed facebook's instructions on how to get it using the java SDK with a commandline call. Turns out it was false. I entered in "12345" in my facebook apps hash key. Then download the app "logcat", run your app and you will get the normal error that I had, and just click "okay" on the error that comes up. Then open "logcat", and you will find an error that has the facebook login error, and it will tell you the correct hash key there. Entered the one shown there and now my facebook login error is resolved, huzzah! hope this helps others.
uid: 19620 topic_id: 32551 reply_id: 129855


[TOPIC: post.html]
#18

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

I'm glad you got it working!

Yeah, setting up facebook with the wrong hash key is by far the most common issue and it comes up on our forums several times a week. It's to the point where I think us documenting it just isn't enough. We might have to get a little more aggressive about it and just display an alert dialog to inform the developer, "Hey! Listen! Your hash key is wrong! Use this hash key!"... but state it in a nicer way of course. :)
uid: 32256 topic_id: 32551 reply_id: 129927


[TOPIC: post.html]
#19

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Contributor

  • 751 posts
  • Corona SDK

Yea maybe create a blog post and then link to it on the documentation pages that talk about facebook connectivity. Would save people lots of time!
uid: 19620 topic_id: 32551 reply_id: 130022


[TOPIC: post.html]
#20

WarrenW

[GLOBAL: userInfoPane.html]
WarrenW
  • Contributor

  • 830 posts
  • Corona SDK

Thanks for this information. It will be very helpful while working on my Facebook app.

Do you know how to save a picture from the camera to sent to my Facebook page? I made a post about this and have not gotten any replies. I even posted I would pay for an answer.

Thanks!
uid: 184193 topic_id: 32551 reply_id: 130024


[TOPIC: post.html]
#21

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Contributor

  • 751 posts
  • Corona SDK

Well I know how to save a picture from the corona display screen, but not from the phones camera. For this scenario you can use "display.save". Sorry not sure about using the phones camera
uid: 19620 topic_id: 32551 reply_id: 130033


[TOPIC: post.html]
#22

WarrenW

[GLOBAL: userInfoPane.html]
WarrenW
  • Contributor

  • 830 posts
  • Corona SDK

The following code grabs a picture from the camera and is loaded into the image variable. Do you know how to save the image from here to file?

-- 
-- Abstract: Camera sample app
-- 
-- Version: 1.2
-- 
-- Updated: September 21, 2011
--
-- Update History:
-- 	v1.1	Fixed logic problem where it said "session was cancelled".
--	v1.2	Added Android support.
--
-- Sample code is MIT licensed, see http://www.coronalabs.com/links/code/license
-- Copyright (C) 2011 Corona Labs Inc. All Rights Reserved.
---------------------------------------------------------------------------------------
-- Camera not supported on simulator.                    
local isXcodeSimulator = "iPhone Simulator" == system.getInfo("model")
if (isXcodeSimulator) then
	 local alert = native.showAlert( "Information", "Camera API not available on iOS Simulator.", { "OK"})    
end

--
local bkgd = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
bkgd:setFillColor( 128, 0, 0 )

local text = display.newText( "Tap anywhere to launch Camera", 0, 0, nil, 16 )
text:setTextColor( 255, 255, 255 )
text.x = 0.5 * display.contentWidth
text.y = 0.5 * display.contentHeight

local sessionComplete = function(event)	
	local image = event.target

	print( "Camera ", ( image and "returned an image" ) or "session was cancelled" )
	print( "event name: " .. event.name )
	print( "target: " .. tostring( image ) )

	if image then
		-- center image on screen
		image.x = display.contentWidth/2
		image.y = display.contentHeight/2
		local w = image.width
		local h = image.height
		print( "w,h = ".. w .."," .. h )
		native.showAlert("Corona", "See image???")
	end
end

local listener = function( event )
	if media.hasSource( media.Camera ) then
		media.show( media.Camera, sessionComplete )
	else
		native.showAlert("Corona", "Camera not found.")
	end
	return true
end
bkgd:addEventListener( "tap", listener )
uid: 184193 topic_id: 32551 reply_id: 130038


[TOPIC: post.html]
#23

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Have a look at the following blog post on how to upload photos to facebook...
http://www.coronalabs.com/blog/2011/12/16/uploading-photos-to-facebook-in-corona/

When calling media.show() to take a picture with the camera, I highly recommend that you set the 3rd argument so that it will save to file. This allows your app to receive a full sized photo from the camera. If you do not set the 3rd argument, then your app will receive a reduced sized photo that will appear on screen. The reason the photo is reduced in size is to fit within the OpenGL rendering system max texture size limit and also due to memory limitations on low-end Android devices. Have a look at the following API documentation for more details...
http://docs.coronalabs.com/api/library/media/show.html

I hope this helps!
uid: 32256 topic_id: 32551 reply_id: 130039


[TOPIC: post.html]
#24

rxmarccall

[GLOBAL: userInfoPane.html]
rxmarccall
  • Contributor

  • 751 posts
  • Corona SDK

@Joshua,
I am using display.save to capture the screen. In the simulator I can look in the corona sandbox and see the saved image, however when I then upload it to share on facebook, the image looked all stretched and skewed in a weird way, have you come across this issue before?
uid: 19620 topic_id: 32551 reply_id: 130046


[TOPIC: post.html]
#25

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

I haven't seen that issue before. Try e-mailing the image file that was created by display.save() to yourself to verify that the file is okay. You can do so via our
native.showPopup()
API.
http://docs.coronalabs.com/api/library/native/showPopup.html

If the e-mail image file is okay, then we know it's a facebook issue that we have to work-around.
uid: 32256 topic_id: 32551 reply_id: 130051



[topic_controls]
Page 1 of 3 1 2 3
 
[/topic_controls]