Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
squirreltown
Roku Guru

Twitter Oauth Example Fix

The TwitterOauth example source in the SDk (2011) was broken when Twitter upgraded their API to 1.1 from 1.0.
To stop it from crashing replace the following functions in twitter.brs with the ones posted below. Please note the comments.

Function parse_status_response(json As Object, tweetArray As Object) As Void

tweetCount = 0

for each array in json
array = tweet
end for

for each tweet in json

item = init_tweet_item()

item.Message = tweet.text
item.UserName = tweet.user.screen_name
item.ImageSource = tweet.user.profile_image_url

tweetCount = tweetCount + 1
tweetArray.Push(item)

end for

End Function


Function show_tweet_canvas() As Void

http = NewHttp("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=RokuUser") 'need to replace RokuUser with actual screen name
oa = Oauth()
oa.sign(http,true)
rsp = http.getToStringWithTimeout(10)
json = ParseJson(rsp)

if json=invalid then
print "Can't parse feed"
sleep(25)
return
endif

tweetArray = CreateObject("roArray", 100, true)
m.ParseTweets(json, tweetArray)

canvasArray = CreateObject("roArray", 100, true)
canvasCount = 0
tweetCount% = 0
tweetColumn% = 0
tweetRow% = 0
for each tweet in tweetArray

canvasItem = CreateObject("roAssociativeArray")
canvasItem.url = tweet.ImageSource
targetRect = CreateObject("roAssociativeArray")
targetRect.x = tweetColumn% * 540 + 36
targetRect.y = tweetRow% * 165 + 36 'changed 135 to 165
targetRect.w = 48
targetRect.h = 48
canvasItem.TargetRect = targetRect
canvasCount = canvasCount + 1
canvasArray.Push(canvasItem)

canvasItem = CreateObject("roAssociativeArray")
canvasItem.Text = tweet.UserName
canvasItem.TextAttrs = {Color:"#FFC8AB14", Font:"Medium", HAlign:"HLeft",VAlign:"VCenter", Direction:"LeftToRight"}
targetRect = CreateObject("roAssociativeArray")
targetRect.x = tweetColumn% * 540 + 60 + 36
targetRect.y = tweetRow% * 165 + 36 'changed 135 to 165
targetRect.w = 210
targetRect.h = 45
canvasItem.TargetRect = targetRect
canvasCount = canvasCount + 1
canvasArray.Push(canvasItem)

canvasItem = CreateObject("roAssociativeArray")
canvasItem.Text = tweet.Message
canvasItem.TextAttrs = {Color:"#FFCCCCCC", Font:"Medium", HAlign:"HLeft",VAlign:"VCenter", Direction:"LeftToRight"}
targetRect = CreateObject("roAssociativeArray")
targetRect.x = tweetColumn% * 540 + 60 + 36
targetRect.y = tweetRow% * 165 + 36 + 65 'changed 45 to 65, 135 to 165
targetRect.w = 480 '
targetRect.h = 90 ' two rows of text
canvasItem.TargetRect = targetRect
canvasCount = canvasCount + 1
canvasArray.Push(canvasItem)

tweetCount% = tweetCount% + 1
tweetColumn% = tweetCount% / 4
tweetRow% = tweetCount% - (tweetColumn% * 4)

print "tweetColumn% = "; tweetColumn%; "tweetRow% = ";tweetRow%

' only 8 tweets displayed on HD screen
if tweetCount% = 8 then
exit for
endif

end for

showImageCanvas(canvasArray)

End Function
Kinetics Screensavers
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.