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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | local function escape (s) s = string.gsub(s, "([&=+%c])", function (c) return string.format("%%%02X", string.byte(c)) 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 |
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...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | ----------------------------- -- 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 fbName = "App Name" native.showWebPopup(20, 20, display.contentWidth - 40, display.contentHeight - 90, "http://www.facebook.com/dialog/feed?display=touch&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 |
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?
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?
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 :)
-finefin