Alternate way to use Facebook and Twitter in app?

Hello,
I have been implementing Twitter into my app, and ran into some trouble getting OAuth and all that other stuff to work well. So, while I was looking for other solutions, I found this code on Peach Pellen’s blog, which is basically the equivalent of a “Tweet” button on a website, that allows me to open a web popup and set a default text for the user to tweet.
[lua]local function escape (s)
s = string.gsub(s, “([&=+%c])”, function ©
return string.format("%%%02X", string.byte©)
end)
s = string.gsub(s, " ", “+”)
return s
end
tweetText = “This is the default text of your tweet”
local postBody = escape( tweetText )
local theNetwork = theNetwork or “twitter” – twitter is default

–local theString = string.gsub(message, “( )”, “%%20”)

TwitterButtonRelease = function(event)
if theNetwork == theNetwork or “twitter” then
native.showWebPopup(0, 35, 480, 285, “http://twitter.com/intent/tweet?text=”…postBody)
end[/lua]
As you can see, it directs the user to a link on twitter, when the user is requested to login, and then is prompted to tweet the text.
(You can try it out here)
I was wondering if there is an equivalent to this code that works for Facebook.
I would love to avoid using Facebook connect, because Facebook recently decided that my account was under a fake name (Which it is not), and I have to submit an appeal to them. I have heard that appeals can take weeks to complete, but I would like to get my app out sooner than that.
So, if anyone knows a link that allows you to set the text for the user to post to Facebook, please help.
Thanks in advance! [import]uid: 38000 topic_id: 19775 reply_id: 319775[/import]

Can you explain the four parameters that you use in the Facebook link? “Message” is understandable, but how does the image, the link, and the name fit into in the post? Also, is the redirect URL a webpage that you are sent to after you post? [import]uid: 38000 topic_id: 19775 reply_id: 76820[/import]

One more question: when I go to the link on the simulators, it just shows a white webpopup. However, when I go to the link in my browser, it redirects me to another page, which, if I cut and paste into my code, does load in the simulator. Do you (or anyone else) know why this happens? [import]uid: 38000 topic_id: 19775 reply_id: 76835[/import]

for facebook dialog feed reference, see
http://developers.facebook.com/docs/reference/dialogs/feed/

as for the white screen: you must test this on a device.
see http://developer.anscamobile.com/reference/index/nativeshowwebpopup for more info

unfortunately native.showWebPopup() does not return anything. that means we can’t check if the web page has loaded or not. If anyone has an idea how to implement callbacks for the web popup, please let me know.

happy new year :slight_smile:
-finefin

[import]uid: 70635 topic_id: 19775 reply_id: 76869[/import]

At last I have Twitter working using this code

However how do you close the window?

I can’t see any links on the Twitter pop-up

Help really appreciated on this, been working since before before Christmas trying to add Twitter / Facebook on my App so I can launch
[import]uid: 3093 topic_id: 19775 reply_id: 77302[/import]

@dominic you need to close the webPopup from *outside* the view.
take a look at my snippet above:

  • a webGroup, that is slightly bigger than the screen, is created.
  • a newRect (backBtn) is created and put in webGroup.
  • the webPopup, that is *smaller than the screen*, opens on top of that.
  • when the button of webGroup is pressed, webGroup and webPopup close.

cheers
-finefin
[import]uid: 70635 topic_id: 19775 reply_id: 77312[/import]

thanks for your help all working! [import]uid: 3093 topic_id: 19775 reply_id: 77333[/import]

Can the redirect link be to a local file? That way, you could redirect the user back to the app when they finish. [import]uid: 38000 topic_id: 19775 reply_id: 77362[/import]

I just tried this on the Xcode simulator, and this code:
[lua]local message = “Test”
local theString = string.gsub(message, “( )”, “%%20”)
local redirectUri = “http://www.google.com/
local fbLink = “http://www.google.com/
local fbName = “My App”
native.showWebPopup(0, 35 + display.screenOriginY, 480, display.contentHeight + 35 + display.screenOriginY, “http://m.facebook.com/dialog/feed?display=touch&redirect_uri="..redirectUri.."&link="..fbLink.."&name="..fbName.."&description=”…theString)[/lua]
doesn’t open a popup. My back button shows up fine, but the rest doesn’t work,
Additionally, in my browser, I get an error from Facebook saying “An error occurred. Please try again later.”
I can’t tell why either of these happens. Does anyone see anything wrong with my code or my parameters in the Facebook link?
Thanks for all your help!

[import]uid: 38000 topic_id: 19775 reply_id: 77408[/import]

Appreciate some help on the Facebook example now I have Twitter working :slight_smile:

I may just be having the same issues as the post above.

Does the code above have everything I need ? I’ve tried as is, and also read up on the links, setting the values to be the same as the Direct URL example

Maybe the sticking point is the App_Id? Do we need an App_ID or key? its not in your example. I’ve tried the one in the link eg app_id=123050457758183

Does fb_name need to be an actual FB App? or will “App Name” be OK? I also tried setting it to “Facebook Dialogs” as the examples in the link

I’ve tried to get this working most of today, would be great if you could shed a little more light on what’s required here

Thanks

[import]uid: 3093 topic_id: 19775 reply_id: 77566[/import]

@peter fbName and all strings have to be url encoded to make this work. change “My App” to “My%20App” and it should work.

@dominic afaik you don’t need an app ID for facebook dialog feed, maybe the error is also caused by the SPACE character in the app name string… ?

-finefin [import]uid: 70635 topic_id: 19775 reply_id: 77577[/import]

that works thanks!

so to repeat use the example as ignoring my previous post is but make sure you URL encode all strings, so “My App” becomes “My%20App” [import]uid: 3093 topic_id: 19775 reply_id: 77583[/import]

I accordingly edited my snippet. [import]uid: 70635 topic_id: 19775 reply_id: 77590[/import]

@dominic.wood
I wasn’t able to get it working. I am still being sent to the “An error occurred” after I login , even when using @canupa’s code. Can you share your working code? [import]uid: 38000 topic_id: 19775 reply_id: 77670[/import]

Actually it didn’t work for me without the App_ID. I’m sure the code above will work with the ID but as requested this worked for me - now working in the simulator too!
–a copy of working code below

local app_id=“123050457758183” --copied this from the docs
local fbLink=“http://developers.facebook.com/docs/reference/dialogs/” --displayed link will go there if clicked
local fbPic=“http://fbrell.com/f8.jpg” --image see guidelines on aspect ratio
local fbName=“Facebook%20Dialogs” --appears in Bold any but needs URL encoding no spaces

local theString=“Facebook%20Dialogs%20are%20so%20easy!”
local redirectUri=“http://www.example.com/response” --where it goes after post

native.showWebPopup(display.contentWidth*0.03, display.contentHeight*0.26, display.contentWidth*0.94, display.contentHeight*0.65, “http://www.facebook.com/dialog/feed?display=touch&app_id="..app_id.."&redirect_uri="..redirectUri.."&link="..fbLink.."&picture="..fbPic.."&name="..fbName.."&caption="..caption.."&description="..theString.."&message=”…theString)
[import]uid: 3093 topic_id: 19775 reply_id: 77743[/import]

yes, there’s a similar url call for facebook.
here’s a function I wrote to post on twitter OR facebook.
It also generates a web popup on top of a black background.
Tap on the background to close the view…

-----------------------------  
-- Send String to Social Network --  
----------------------------  
-- example: fin.sendSocial ( string, "facebook" )  
-----------------  
  
fin.sendSocial = function (theMessage, theNetwork)  
 local theNetwork = theNetwork or "twitter" -- twitter is default  
 local webGroup = display.newGroup()  
 local message = theMessage or "NO TITLE..."  
 webGroup:toFront()  
 local theString = string.gsub(message, "( )", "%%20")  
 if theNetwork == "twitter" then   
 native.showWebPopup(20, 20, display.contentWidth - 40, display.contentHeight - 90, "http://twitter.com/intent/tweet?text="..theString)  
 elseif theNetwork == "facebook" then  
 local redirectUri = "http://www.canupa.com/"  
 local fbLink = "http://www.canupa.com/products/"  
 local fbPic = "http://canupa.com/images/stories/canupa\_logo\_tm.jpg"  
 local app\_id = "1234xxxxxx"  
 local fbName = "My%20App"  
 native.showWebPopup(20, 20, display.contentWidth - 40, display.contentHeight - 90, "http://www.facebook.com/dialog/feed?display=touch&app\_id="..app\_id.."&redirect\_uri="..redirectUri.."&link="..fbLink.."&picture="..fbPic.."&name="..fbName.."&description="..theString)  
 end  
  
 local backBtn = display.newRect( webGroup, -30, -30, display.contentWidth+30, display.contentHeight+30 )  
 backBtn:setFillColor(0,0,0)  
 backBtn.alpha = 0.4  
  
 local btn\_touch = {}  
 local btn\_touch\_began = {}  
 function closeWebPopup()  
 webGroup.isVisible = false  
 native.cancelWebPopup()  
 end  
 function btn\_touch ( event )  
 if "began" == event.phase then  
 closeWebPopup()  
 end  
 end  
 backBtn:addEventListener ( "touch", btn\_touch )   
end  
  

cheers
-finefin [import]uid: 70635 topic_id: 19775 reply_id: 76644[/import]

just tested and it works without a specified app_id,
facebook docs say it’s required, 'tho.
don’t know, but I can use feed dialog without it… strange.

:confused:

-finefin

EDIT: aaahahaha, I’m so sorry. I re-checked the code of the FB-post in my game and I actually send the app_id, too. sry

EDIT II: to add an app to get an individual app_id, go to
https://developers.facebook.com/apps – I forgot about this step.

EDIT III: … and again, I fixed my snippet :wink: [import]uid: 70635 topic_id: 19775 reply_id: 77744[/import]

OMG, @finfin, I’m working to integrate FB and your code snippet works nicely.

On FB developer/app screen, I could not enable Native iOS App (because my game isn’t published yet), and then I thought maybe that would be a real stumble block…

Anyhow, I’m wondering if I could add/show “like” button. On this page, it says:

What happened to the old Share button?

We deprecated the Share Button when we launched the Like button, because the Like button improves clickthrough rates by allowing users to connect with one click, and by allowing them to see which of their friends have already connected. For reference, the Share button documentation is still available here.

With your code snippet, though, I see the share button instead of like button.

Also, I’m wondering what might be the real difference between your code and what is presented in the CoronaSDK > SampleCode > Networking > Facebook folder. Is there a strong advantage in working out the sample code method rather than the alternative code you’ve posted? It looks like a lot more complex way to do it (and thus, your code snippet feels like a god-sent), but honestly, if we could figure out how it works, would you say it would be better to implement how it is meant to be done?

Anyhow, thanks again for sharing your code. I feel I’m getting a step closer to finalizing my game.

Naomi

Edit: I was able to implement the Facebook API after all. The sample code that comes with Corona SDK works nicely. That said, I’d say, the alternative method provided under this thread was super easy to implement, and got me over the mental block I got through the App ID creation process at Facebook. Thanks!

Edit2: Also note, I’m using Daily Build 706, which doesn’t include FB single sign on feature. Perhaps with the build 707 and above, I could implement the “like” button, but for now, I’m happy with what I got. [import]uid: 67217 topic_id: 19775 reply_id: 82796[/import]

Naomi,
Did you get it working without enabling it as a native iOS app in Facebook? I thought you had to do that first, so I was just waiting until I was just about to submit to apple. [import]uid: 38000 topic_id: 19775 reply_id: 83209[/import]

Hey, @peter9221, yes, I got it working. I’ve noted how I went about it here:

https://developer.anscamobile.com/forum/2012/01/27/help-facebook-api-how-integrate-test-unpublished-app

It pretty much describes the path I took to overcome the issue. I hope it helps.

Naomi [import]uid: 67217 topic_id: 19775 reply_id: 83223[/import]