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:
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
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
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.
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?
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.