Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Easy Twitter integration
Started by spjnowak May 05 2011 09:17 AM

40 replies to this topic
[TOPIC CONTROLS]
Page 1 of 2 1 2
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

spjnowak

[GLOBAL: userInfoPane.html]
spjnowak
  • Pro
  • PipPipPipPipPipPip
  • 109 posts
  • Jedi

I thought you might find this a useful tip.

I spent ages with the oAuth code samples getting an app to send a simple tweet before I realised that there is an extremely simple way of doing, with no need to register your app with Twitter or use access keys. Use Twitter Web Intents (see the developer pages on the Twitter website for more details).

Just one line of code to send a tweet ...

native.showWebPopup(0, 0, 320, 480, "http://twitter.com/intent/tweet?text=My%20tweet%20goes%20here")

As well as the text parameter you can also use
url
via
hashtag

The text and url parameters should be URL encoded. The user signs in to their twitter account in the web popup which then shows them the message (which can be edited) and the Tweet button.

You'll want to make the web popup less than full-screen to allow for a button to close the popup and return to your app. The user doesn't have to log in next time you call the popup so it's great for quickly posting scores etc. during a game.

Simple as that!

Stefan
uid: 2646 topic_id: 9695 reply_id: 309695


[TOPIC: post.html]
#2

peach pellen

[GLOBAL: userInfoPane.html]
peach pellen
  • Alumni
  • PipPipPipPipPipPip
  • 8,866 posts
  • Jedi

I'm bumping this to keep it on the front a bit longer.

Very valuable info for the many users wanting a simpler way to integrate Twitter.

Nicely done! :)
uid: 52491 topic_id: 9695 reply_id: 35699


[TOPIC: post.html]
#3

MiClosStudio

[GLOBAL: userInfoPane.html]
MiClosStudio
  • Pro
  • PipPipPipPipPipPip
  • 118 posts
  • Jedi

Great! Thanxxx

Michael
uid: 25327 topic_id: 9695 reply_id: 35704


[TOPIC: post.html]
#4

Yobonja

[GLOBAL: userInfoPane.html]
Yobonja
  • Pro
  • PipPipPipPipPipPip
  • 196 posts
  • Jedi

Cool, I think I'll use this for bragging about score. Thanks!

-Angelo
uid: 12822 topic_id: 9695 reply_id: 35706


[TOPIC: post.html]
#5

spjnowak

[GLOBAL: userInfoPane.html]
spjnowak
  • Pro
  • PipPipPipPipPipPip
  • 109 posts
  • Jedi

Thanks, Peach. I've been trying a similar thing with Facebook, using the Dialog URL (details here http://developers.facebook.com/docs/reference/dialogs/). It works rather well and also allows the user to edit their post. You need to set the display parameter to touch so that the dialog fits the screen nicely. If you're not logged on then you get the login dialog first.

Here's an example:

native.showWebPopup(0, 80, screenW, screenH-80, "http://www.facebook.com/dialog/feed?display=touch&redirect_uri=http://www.yourwebsite.com&app_id=" .. appId .. "&link=http://www.yourwebsite.com/yourapp&picture=http://www.yourwebsite.com/appicon.png&name=Your%20App&caption=iPhone%20app%20coming%20soon&description=Put%20your%20description%20text%20here&message=" .. messageText)

As with my Twitter example, leave a space above (or below) the web popup to put in a button to return to your app (i.e. to cancel the web popup).

Simple (again)!

Stefan
uid: 2646 topic_id: 9695 reply_id: 35711


[TOPIC: post.html]
#6

azone

[GLOBAL: userInfoPane.html]
azone
  • Starter
  • PipPipPipPipPipPip
  • 70 posts
  • Jedi

Hi Stefan,
I tried the Twitter and Facebook codes and they work.
But there is one thing that doesn't work properly.

After posting a twitter message the window closes correctly but after posting the Facebook message the popup window stays and displays the content of my website.

Do you know how to fix it please?

Thank you, :)
Dusan

uid: 5411 topic_id: 9695 reply_id: 42591


[TOPIC: post.html]
#7

spjnowak

[GLOBAL: userInfoPane.html]
spjnowak
  • Pro
  • PipPipPipPipPipPip
  • 109 posts
  • Jedi

Hi Dusan

As mentioned in my previous post, you need to make the popup window less than full-screen to leave a space to put a button that can be used to cancel the popup after posting your message. This is also useful if the user decides not to post the message or if there is a connection problem.

Hope that helps!

Stefan
uid: 2646 topic_id: 9695 reply_id: 42603


[TOPIC: post.html]
#8

azone

[GLOBAL: userInfoPane.html]
azone
  • Starter
  • PipPipPipPipPipPip
  • 70 posts
  • Jedi

I made it smaller and put the close button there.
I just wasn't sure if it's the right behavior that my web site appears in the web popup after the facebook message is sent. I wish the web popup would close itself as it does in the twitter case.

Thanks a lot!,
Dusan
uid: 5411 topic_id: 9695 reply_id: 42606


[TOPIC: post.html]
#9

spjnowak

[GLOBAL: userInfoPane.html]
spjnowak
  • Pro
  • PipPipPipPipPipPip
  • 109 posts
  • Jedi

I can't remember the exact behaviour but I thought you had to manually close the web popup for both the Twitter and Facebook examples. If you want this to happen automatically then I think you'll need to use the oAuth approach.

Stefan
uid: 2646 topic_id: 9695 reply_id: 42608


[TOPIC: post.html]
#10

azone

[GLOBAL: userInfoPane.html]
azone
  • Starter
  • PipPipPipPipPipPip
  • 70 posts
  • Jedi

Hi Stefan,
I just tested both examples (Facebook and Twitter) on Android device and found out that they crash after I try to login.

Have you tested it on Android and do you have the same experience?

Thanks,
Dusan

uid: 5411 topic_id: 9695 reply_id: 42723


[TOPIC: post.html]
#11

spjnowak

[GLOBAL: userInfoPane.html]
spjnowak
  • Pro
  • PipPipPipPipPipPip
  • 109 posts
  • Jedi

Hi Dusan

I haven't tested out the Facebook and Twitter examples on Android yet (I've only recently got an Android device) but I can't see any reason why they should not work. The code is essentially the same as is used to create simple website widgets, and is based on Facebook and Twitter documentation, with the Corona web popup acting as the medium.

I would suspect that the most likely cause of any failure would be not having the appropriate Internet permissions in the build.settings file. I can't recall the exact format details off the top of my head but there are several references to the settings required elsewhere on the Ansca forums and reference pages.

I'll try and have a go myself but let me know if you have any success.

Stefan
uid: 2646 topic_id: 9695 reply_id: 42755


[TOPIC: post.html]
#12

mimetic

[GLOBAL: userInfoPane.html]
mimetic
  • Pro
  • PipPipPipPipPipPip
  • 104 posts
  • Jedi

SO FRUSTRATING!!!

Twitter intents sometimes close the window, and sometimes they don't!!! Sometimes I get an ad for the Twitter iPad app, sometimes something else. Argh!!!!!

I built a close button and a background rect to hide the screen. That means, sometimes I'm left with a blank screen and a close button. Sure, it works, but it isn't elegant!!!!

Argh, I say.
uid: 37366 topic_id: 9695 reply_id: 46784


[TOPIC: post.html]
#13

azone

[GLOBAL: userInfoPane.html]
azone
  • Starter
  • PipPipPipPipPipPip
  • 70 posts
  • Jedi

He Mimetic, what Corona SDK build do you use?

D.
uid: 5411 topic_id: 9695 reply_id: 46785


[TOPIC: post.html]
#14

mimetic

[GLOBAL: userInfoPane.html]
mimetic
  • Pro
  • PipPipPipPipPipPip
  • 104 posts
  • Jedi

Unsure which version that was, I think a a two-week old "daily". I've just downloaded the latest daily build (2011.585). The issue seems to be on the Twitter side, what with their big ad and all. If they had a window like the Facebook window, with a close button, it might work better!
uid: 37366 topic_id: 9695 reply_id: 46823


[TOPIC: post.html]
#15

macman223

[GLOBAL: userInfoPane.html]
macman223
  • Pro
  • PipPipPipPipPipPip
  • 100 posts
  • Jedi

Hello,

I used the above code and it works great, but I can't get a hashtag to appear. Can someone provide a sample of how to properly do this?

Thanks.

Update: I figured it out!
uid: 47722 topic_id: 9695 reply_id: 48849


[TOPIC: post.html]
#16

canupa.com

[GLOBAL: userInfoPane.html]
canupa.com
  • Pro
  • PipPipPipPipPipPip
  • 450 posts
  • Jedi

uh. the facebook example worked like a charm a few days ago.
but now it's not working anymore!

the "message" isn't sent :(
but I changed nothing since the last successful test...

I try this:

http://www.facebook.com/dialog/feed?display=touch&redirect_uri=http://www.canupa.com/products&app_id=xxxxxxxxx&link=http://www.canupa.com/products/parallax&picture=http://www.canupa.com/images/stories/articles/appicon_parallax_80x80_01.png&name=PARALLAX&message=WOW!%20I%20scored%20100000%20in%20PARALLAX!%20RANK%3A%20A%20-%20challenge%20me!%20http%3A%2F%2Fitunes.apple.com%2Fapp%2Fparallax%2Fid445444981%3Fmt%3D8
(in my project the score and rank are added dynamically)

I guess facebook changed something?
It's not working in the browser either,
so this one is not on anscas side, i guess - wich is a good thing :)

the twitter webPopup works perfectly, btw...

EDIT: okay facebook changed it:

message	

This field will be ignored on July 12, 2011 The message to prefill the text field that the user will type in. To be compliant with Facebook Platform Policies, your application may only set this field if the user manually generated the content earlier in the workflow. Most applications should not set this.

my idea is to put the "message" into the link description section... yeah, that should work. will report after testing...

EDIT2: yes, that works quite nicely and looks even better than before :)
uid: 70635 topic_id: 9695 reply_id: 49182


[TOPIC: post.html]
#17

JRQ

[GLOBAL: userInfoPane.html]
JRQ
  • Starter
  • PipPip
  • 14 posts
  • Member

this info was extremely helpful....for others looking for more information check this link on facebook about new changes in feed dialogs: http://developers.facebook.com/docs/reference/dialogs/feed/
uid: 9546 topic_id: 9695 reply_id: 49278


[TOPIC: post.html]
#18

canupa.com

[GLOBAL: userInfoPane.html]
canupa.com
  • Pro
  • PipPipPipPipPipPip
  • 450 posts
  • Jedi

here's another problem I stumbled upon regarding twitter web popups-

Lets say you have a string you want to tweet that looks like this:
message = "Hi everybody! This is a tweet full of space characters!"
as the tweet says: there are a lot of spaces.
If you do this:
native.showWebPopup(0, 0, 320, 300, "http://twitter.com/intent/tweet?text="..message)
...the whole thing would not work because the string has to be URL encoded. I don't find any API for url encoding (but if there is, please tell me!)

So, I did the following to encode my string and replace every SPACE-character with "%20"

local theString = string.gsub(message, "( )", "%%20")
native.showWebPopup(0, 0, 320, 300, "http://twitter.com/intent/tweet?text="..theString)

cheers
-finefin
uid: 70635 topic_id: 9695 reply_id: 56490


[TOPIC: post.html]
#19

JRQ

[GLOBAL: userInfoPane.html]
JRQ
  • Starter
  • PipPip
  • 14 posts
  • Member

Yes, there's a way to encode URLs in Lua, it's easy. First make sure you load the socket library at the beginning of your code, and then use the url.escape command, here's an example:

[lua=auto:0]url = require("socket.url")
text = url.escape(string)
uid: 9546 topic_id: 9695 reply_id: 56515


[TOPIC: post.html]
#20

canupa.com

[GLOBAL: userInfoPane.html]
canupa.com
  • Pro
  • PipPipPipPipPipPip
  • 450 posts
  • Jedi

great! thank you!
uid: 70635 topic_id: 9695 reply_id: 56516


[TOPIC: post.html]
#21

neil6

[GLOBAL: userInfoPane.html]
neil6
  • Starter
  • PipPipPipPipPipPip
  • 84 posts
  • Jedi

Hi, I have this installed and working - thank you! - but if I have no Internet connection the popup does not display?

Is there a way to determine if user has connection before attempting to display the page?

Thanks
uid: 125592 topic_id: 9695 reply_id: 102056


[TOPIC: post.html]
#22

spjnowak

[GLOBAL: userInfoPane.html]
spjnowak
  • Pro
  • PipPipPipPipPipPip
  • 109 posts
  • Jedi

This is code that I have used in the past


local networkAvailable = false
function MyNetworkReachabilityListener( event )
		if event.isReachable then
			networkAvailable = true
			print("online")
                        -- do something here if online
		else
			networkAvailable = false
			print("offline")
                        -- do something here if offline
		end
end

function checkOnline()
	if network.canDetectNetworkStatusChanges then
		network.setStatusListener( "www.twiiter.com", MyNetworkReachabilityListener )
	else
                print("network reachability not supported on this platform")
		networkAvailable = false
	end
end

Hope that helps!

Stefan
uid: 2646 topic_id: 9695 reply_id: 102058


[TOPIC: post.html]
#23

pixiogame

[GLOBAL: userInfoPane.html]
pixiogame
  • Pro
  • PipPip
  • 15 posts
  • Member

well noted. great.
uid: 63983 topic_id: 9695 reply_id: 104741


[TOPIC: post.html]
#24

Bladko

[GLOBAL: userInfoPane.html]
Bladko
  • Pro
  • PipPipPipPipPipPip
  • 338 posts
  • Jedi

Is there any kind of remote method to twit ?

https://mobile.twitter.com/intent/tweet&text=Blablabla

But for a mobile device ?

PS: would be nice to have Twitter API just like Facebook API in Corona.

Tom
uid: 111283 topic_id: 9695 reply_id: 106393


[TOPIC: post.html]
#25

taddmencer

[GLOBAL: userInfoPane.html]
taddmencer
  • Pro
  • PipPipPip
  • 48 posts
  • Advanced Member

Has anyone had any problems using this methos with Facebook? What happens for me is the webpop launches, but nothing ever loads. The Twitter works, no problem.

Here is my whole code in it's pretty messy entirety.


local fbButton = display.newImage (imgPath .. "Fb_Blue.png")
            fbButton.x = display.contentWidth *.8
            fbButton.y = display.contentHeight * .6
            
            local twButton = display.newImage (imgPath .."Tw_Blue.png")
            twButton.x = display.contentWidth *.7
            twButton.y = display.contentHeight *.6
            
            local closeButton
            local webPopBG
            
            function closeWindow(event)
                native.cancelWebPopup() 
                if closeButton ~= nil and closeButton.removeSelf then 
                    closeButton:removeSelf( ) 
                end 
                if webPopBG ~= nil and webPopBG.removeSelf then
                    webPopBG:removeSelf() 
                end
            end
            
            
            local function callTW(event)
                if event.phase == "ended" then
                    closeButton = display.newImage(imgPath .."closeBack.png")
                    closeButton.x = display.contentWidth *.75
                    closeButton.y = 30
                    closeButton:addEventListener("touch",closeWindow)
                    
                    webPopBG = display.newRect(0,0,display.contentWidth, display.contentHeight)
                    webPopBG:setFillColor(0,0,0,50)
                    
                    local message = "I got " ..scoreInfo.. " on Circus Big Pop Lite! Can you beat that? http://itunes.apple.com/us/app/circus-big-pop-lite/id521759035?ls=1&mt=8"
                    local theString = string.gsub(message, "( )", "%%20")
                    native.showWebPopup( 20,40,display.contentWidth *.8 ,display.contentHeight *.8, "https://twitter.com/intent/tweet?text=" ..theString)              
                end
                
            end
            
            
            local function callFB (event)
                if event.phase == "ended" then
                    closeButton = display.newImage(imgPath .."closeBack.png")
                    closeButton.x = display.contentWidth *.75
                    closeButton.y = 30
                    closeButton:addEventListener("touch",closeWindow)
                    
                    webPopBG = display.newRect(0,0,display.contentWidth, display.contentHeight)
                    webPopBG:setFillColor(0,0,0,50)
                    
                    local fbMessage = "I got " ..scoreInfo.. " on Circus Big Pop Lite!"
                    
                    native.showWebPopup( 20,40,display.contentWidth *.8 ,display.contentHeight *.8, "https://facebook.com/dialog/feed?app_id=343967615657719&link=http://itunes.apple.com/us/app/circus-big-pop-lite/id521759035?ls=1&mt=8&picture=http://c2mpg.com/media/9878/1.jpg&redirect_uri=http://www.facebook.com/CircusBigPop?sk=wall&name=" ..fbMessage.. "&description=Can you beat my score?")
                end 
            end
            
            fbButton:addEventListener("touch", callFB)
            twButton:addEventListener("touch", callTW)

uid: 97023 topic_id: 9695 reply_id: 107112



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