
squirreltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2013
01:11 PM
Tweet out
Hopefully someone (RokuChris?) has messed with this and can help a little. I am trying to send a tweet. I am able to retrieve tweets from a home_timeline or a certain #hashtag no problem. The main difference in sending is its POST instead of GET, and I am not yet able to translate/get the Oauth functions from the SDK Twitter example to attach the authorization the way it does for retrieving timelines.
Here is the working part that gets the timeline:
And here is what i have so far that POSTs without the Oauth attached
In the above example "print out" returns "true" and "print http" returns an array with "base: https://api.twitter.com/1.1/statuses/update.json" as the first item.
I am having trouble understanding what NewHttp() is in the above examples, it looks like a function, but i cant find it anywhere, just references to it.
Kind of stuck, would appreciate any ideas, thanks
here is the complete return from "print http"
"
Here is the working part that gets the timeline:
http = NewHttp("https://api.twitter.com/1.1/statuses/home_timeline.json")
oa = Oauth()
oa.sign(http,true)
rsp = http.getToStringWithTimeout(10)
And here is what i have so far that POSTs without the Oauth attached
strx = screen.GetText()
oa = Oauth()
GT = CreateObject("roUrlTransfer")
GT.SetPort(m.port)
GT.SetURL("https://api.twitter.com/1.1/statuses/update.json" )
http = NewHttp(GT.GetURL())
oa.sign(http,true)
out= GT.AsyncPostFromString( "status=" + strx)
print out
print http
In the above example "print out" returns "true" and "print http" returns an array with "base: https://api.twitter.com/1.1/statuses/update.json" as the first item.
I am having trouble understanding what NewHttp() is in the above examples, it looks like a function, but i cant find it anywhere, just references to it.
Kind of stuck, would appreciate any ideas, thanks
here is the complete return from "print http"
base: https://api.twitter.com/1.1/statuses/update.json
checktimeout: <bsTypedValue: Function>
gettostringwithretry: <bsTypedValue: Function>
retries: 1
dump: <bsTypedValue: Function>
callbackprep: <bsTypedValue: Function>
sync: <bsTypedValue: Function>
protected: true
getparams: <bsTypedValue: Function>
parse: <bsTypedValue: Function>
timer: <Component: roTimespan>
prep: <bsTypedValue: Function>
port: invalid
go: <bsTypedValue: Function>
gettostringwithtimeout: <bsTypedValue: Function>
retry: <bsTypedValue: Function>
receive: <bsTypedValue: Function>
ok: <bsTypedValue: Function>
paramgroup: <bsTypedValue: Function>
addallparams: <bsTypedValue: Function>
removeparam: <bsTypedValue: Function>
anchor:
accessverifier: false
postfromstringwithtimeout: <bsTypedValue: Function>
timestamp: <Component: roTimespan>
wait: <bsTypedValue: Function>
timeout: 5000
addparam: <bsTypedValue: Function>
cancel: <bsTypedValue: Function>
geturl: <bsTypedValue: Function>
label: init
method: GET
"
Kinetics Screensavers
4 REPLIES 4

RokuMarkn
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2013
02:01 PM
Re: Tweet out
You're using AsyncPostFromString which returns immediately, before the response is received. If you want to read the response, you have to listen for an roUrlEvent on the message port associated with the roUrlTransfer object. NewHttp is a utility function that creates the roUrlTransfer object and the message port, and does some initialization. In most of the examples it's in a file called urlUtils.brs.
--Mark
--Mark

squirreltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2013
02:39 PM
Re: Tweet out
Thank you Mark, thats good info, i found it.
Kinetics Screensavers

squirreltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2013
06:38 PM
Re: Tweet out
Now Its sending but its not attaching the "status=" part which is the text of the tweet. I am getting an http 400 error so hopefully this is the only reason for that.
Here is the current relevant part of the function ( I made a copy of the NewHttp() function and changed the method to POST)
Can anyone confirm the last line is the proper syntax, its not attaching to the message so i suspect its wrong, but its not throwing an error.
Also the function NewHttp() is confusing, in urlutilities.brs its method is GET, but has a parameter "this.PostFromStringWithTimeout" (as above) which still shows as a GET request in the output string (like below). So which is it? I have guessed that only works if you change the method to POST which I have done. Is that right?
Thanks
here is whats being sent(redacted):
Here is the current relevant part of the function ( I made a copy of the NewHttp() function and changed the method to POST)
strx = screen.GetText()
oa = Oauth()
http = NewHttpPost("https://api.twitter.com/1.1/statuses/update.json")
oa.sign(http,true)
http.PostFromStringWithTimeout( "status="+ strx ,10)
Can anyone confirm the last line is the proper syntax, its not attaching to the message so i suspect its wrong, but its not throwing an error.
Also the function NewHttp() is confusing, in urlutilities.brs its method is GET, but has a parameter "this.PostFromStringWithTimeout" (as above) which still shows as a GET request in the output string (like below). So which is it? I have guessed that only works if you change the method to POST which I have done. Is that right?
Thanks
here is whats being sent(redacted):
Http: # 418 done status: 400 time: 273ms request: POST https://api.twitter.com/1.1/statuses/update.json
body: oauth_consumer_key=XXX&oauth_nonce=XXX&oauth_signature=XXX&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1383531222&oauth_token=XXX&oauth_version=1.0
Kinetics Screensavers
destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2013
10:47 PM
Re: Tweet out
It's my own understanding that NewHTTPPost isn't a valid routine.
NewHTTP is
Function NewHttp(url As String,port=invalid As Dynamic,method="GET" As String) As Object
So what you would do to initiate a post would be
http=NewHttp("https://api.twitter.com/1.1/statuses/update.json",invalid,"POST")
and then you would add your parameter you want for 'status'
http.AddParam("status","Hello")
Because the method was "POST", the parameters and oauth signing and everything gets alphabetized, encoded, and shoved into the body of the post request to the url.
Setting the oa.sign(http,true) or oa.sign(http,false) or oa.sign(http,false,true) or any combination of true/false for all three variables for that routine don't give me anything other than a 400 response code.
Your postfromstringwithtimeout line is what I think is correct to use there, as intended, but nothing seemed to make a difference there either, even setting the timeout to 1000 or changing the string as well.
I think it's broken. 😞
My app name on twitter is correct, the keys are correct, the allow read and write access is checked and I generated new keys, etc etc... If anyone is able to send a tweet through roku at all, I'd be most grateful.
NewHTTP is
Function NewHttp(url As String,port=invalid As Dynamic,method="GET" As String) As Object
So what you would do to initiate a post would be
http=NewHttp("https://api.twitter.com/1.1/statuses/update.json",invalid,"POST")
and then you would add your parameter you want for 'status'
http.AddParam("status","Hello")
Because the method was "POST", the parameters and oauth signing and everything gets alphabetized, encoded, and shoved into the body of the post request to the url.
Setting the oa.sign(http,true) or oa.sign(http,false) or oa.sign(http,false,true) or any combination of true/false for all three variables for that routine don't give me anything other than a 400 response code.
Your postfromstringwithtimeout line is what I think is correct to use there, as intended, but nothing seemed to make a difference there either, even setting the timeout to 1000 or changing the string as well.
I think it's broken. 😞
My app name on twitter is correct, the keys are correct, the allow read and write access is checked and I generated new keys, etc etc... If anyone is able to send a tweet through roku at all, I'd be most grateful.