Share post on wall - Facebook

Hi guys,

I’m trying to implement a share function into my app but can’t seem to figure it out. I’m using Facebook.v4 atm. First of all, when I login to facebook, the login screen says that “this app does not allow to post”, or something like that. And when I try to post something, the message isn’t posted. Like, the function is called, but nothing happened.

This is my code:

function functions.postFacebook() facebook.request( "me/feed", "POST", { message="Hello Facebook" } ) end function functions.loginFacebook(event) facebook.setFBConnectListener(facebookListener) if ( facebook.isActive ) then accessTokenFacebook = facebook.getCurrentAccessToken() if ( accessTokenFacebook ) then functions.postFacebook() --native.showAlert( "Facebook user already logged in", "User's access token: " .. accessTokenFacebook.token ) else facebook.login() functions.postFacebook() end end return true end

Everything is setup on the facebook dashboard so that should not be a problem, I think, I hope…

Kind regards

Bram

You are not allowed to prefilled text on Facebook, you can only attach images and links

Hi Scott,
I’d read that but thought it would work with Corona because of the “text” parameter. Because I don’t see how that’d be useful otherwise. But okay, another question. Would I be able to link to a local html file? And would I be able to edit that html file through corona? I’d like to make it a personal message but I don’t really see how to do this. I don’t have a server to use.
Kind regards
Bram

First this is a Facebook limitation not a corona limitation. People abused the pre filling of text Facebook banned it and removed this from their api.

  1. you can only post links, so you need a website of some sort. You could post an image which is what most people do.

2. https://docs.coronalabs.com/daily/guide/data/readWriteFiles/index.html (note this is just about editing files nothing to do with Facebook or “partially” about html) 

  1. There are some free web hosts availably (but pretty much all have limitation) 000webhost or wordpress are popular. 

My solution was to display some custom text and score/achievement over a backdrop/paused scene, capture an image with Corona’s APIs and use that as an image to share.

Hi Alex,

So I’ve captured the screen with the captureBounds, but how can I automatically select that picture without the need to make the user go the their gallery and select the screenshot themselves?

Kind regards

Bram

First off there is another api that puts the photo in Documents directory(or temp directory)

https://docs.coronalabs.com/api/library/display/save.html

I would actually do it this way^, because users may not like it if you save a bunch of photos to there photos app when they are just trying to share to Facebook. If I was sharing to Facebook, later looked at my photos app and saw a bunch of photos that I did not want their. I would delete the app. That is just me.

That being said this plugin should help you achieve what you want

https://marketplace.coronalabs.com/plugin/photo-lib-plus

For the record, I was referring to the work flow that Scott described above. Thanks Scott!

Hi, thanks for all the help guys!

I’ve got the capturing done and I’m now working on uploading the file to facebook. This is what I’ve got:

---// FACEBOOK FUNCTIONS \\--- function functions.fbonComplete( event ) if ( event.action == "clicked" ) then local i = event.index if ( i == 1 ) then -- Do nothing; dialog will simply dismiss end end end function functions.facebookListener( event ) if ( "session" == event.type ) then -- Handle login event elseif ( "dialog" == event.type ) then -- Dialog closed end end function functions.postFacebook() local shareParams = { source = {baseDir = system.TemporaryDirectory, filename = "share.png", type = "image"} } facebook.request( "me/feed", "POST", shareParams ) end function functions.loginFacebook(event) facebook.setFBConnectListener(functions.facebookListener) if ( facebook.isActive ) then accessTokenFacebook = facebook.getCurrentAccessToken() if ( accessTokenFacebook ) then print("posting on facebook...") functions.postFacebook() native.showAlert("Your messages is posted successfully!", {"Ok"}, functions.fbonComplete) else facebook.login() print("posting on facebook...") functions.postFacebook() native.showAlert("Your messages is posted successfully!", {"Ok"}, functions.fbonComplete) end end return true end -----------------------------------------------------------------------------------------

But, something is wrong. I’m getting no errors while debugging on my device, but it’s also not uploading. This is how I’ve captured the screen:

function functions.capShareScreen(event) if system.getInfo("model") == "iPhone" or system.getInfo("model") == "iPad" then display.save(popUpIOSGroup, { filename="share.png", baseDir=system.TemporaryDirectory}) else display.save(popUpAndroidGroup, { filename="share.png", baseDir=system.TemporaryDirectory}) end functions.openSharePanel() end

My facebook app is all setup on the facebook developer site and I’m able to login just fine, but uploading won’t work :confused:

Nothing looks wrong at first glance are you sure you are all set in your build.settings?

Hi Scott, I’ve been trying some more to find the bug but can’t find it either. But I’d like to add this to my last post:

I can login to facebook without the app (with a popup screen), but nothing happens when I try to share even though I’m logged in.When the user has the application installed and tries to login into facebook, the follwoing “Login Error” appears: “There is an error in logging you into this application. Please try again later.”… Well, nothing happened after a long wait. My build settings are the exact same as the ones on the documentation page for the plugin, except the App-id.

I also don’t see any problems on my developers app page. I filled in all the required fields and added a platform (Android).

You are not allowed to prefilled text on Facebook, you can only attach images and links

Hi Scott,
I’d read that but thought it would work with Corona because of the “text” parameter. Because I don’t see how that’d be useful otherwise. But okay, another question. Would I be able to link to a local html file? And would I be able to edit that html file through corona? I’d like to make it a personal message but I don’t really see how to do this. I don’t have a server to use.
Kind regards
Bram

First this is a Facebook limitation not a corona limitation. People abused the pre filling of text Facebook banned it and removed this from their api.

  1. you can only post links, so you need a website of some sort. You could post an image which is what most people do.

2. https://docs.coronalabs.com/daily/guide/data/readWriteFiles/index.html (note this is just about editing files nothing to do with Facebook or “partially” about html) 

  1. There are some free web hosts availably (but pretty much all have limitation) 000webhost or wordpress are popular. 

My solution was to display some custom text and score/achievement over a backdrop/paused scene, capture an image with Corona’s APIs and use that as an image to share.

Hi Alex,

So I’ve captured the screen with the captureBounds, but how can I automatically select that picture without the need to make the user go the their gallery and select the screenshot themselves?

Kind regards

Bram

First off there is another api that puts the photo in Documents directory(or temp directory)

https://docs.coronalabs.com/api/library/display/save.html

I would actually do it this way^, because users may not like it if you save a bunch of photos to there photos app when they are just trying to share to Facebook. If I was sharing to Facebook, later looked at my photos app and saw a bunch of photos that I did not want their. I would delete the app. That is just me.

That being said this plugin should help you achieve what you want

https://marketplace.coronalabs.com/plugin/photo-lib-plus

For the record, I was referring to the work flow that Scott described above. Thanks Scott!

Hi, thanks for all the help guys!

I’ve got the capturing done and I’m now working on uploading the file to facebook. This is what I’ve got:

---// FACEBOOK FUNCTIONS \\--- function functions.fbonComplete( event ) if ( event.action == "clicked" ) then local i = event.index if ( i == 1 ) then -- Do nothing; dialog will simply dismiss end end end function functions.facebookListener( event ) if ( "session" == event.type ) then -- Handle login event elseif ( "dialog" == event.type ) then -- Dialog closed end end function functions.postFacebook() local shareParams = { source = {baseDir = system.TemporaryDirectory, filename = "share.png", type = "image"} } facebook.request( "me/feed", "POST", shareParams ) end function functions.loginFacebook(event) facebook.setFBConnectListener(functions.facebookListener) if ( facebook.isActive ) then accessTokenFacebook = facebook.getCurrentAccessToken() if ( accessTokenFacebook ) then print("posting on facebook...") functions.postFacebook() native.showAlert("Your messages is posted successfully!", {"Ok"}, functions.fbonComplete) else facebook.login() print("posting on facebook...") functions.postFacebook() native.showAlert("Your messages is posted successfully!", {"Ok"}, functions.fbonComplete) end end return true end -----------------------------------------------------------------------------------------

But, something is wrong. I’m getting no errors while debugging on my device, but it’s also not uploading. This is how I’ve captured the screen:

function functions.capShareScreen(event) if system.getInfo("model") == "iPhone" or system.getInfo("model") == "iPad" then display.save(popUpIOSGroup, { filename="share.png", baseDir=system.TemporaryDirectory}) else display.save(popUpAndroidGroup, { filename="share.png", baseDir=system.TemporaryDirectory}) end functions.openSharePanel() end

My facebook app is all setup on the facebook developer site and I’m able to login just fine, but uploading won’t work :confused:

Nothing looks wrong at first glance are you sure you are all set in your build.settings?