How to start with oauth and Twitter

Hi, how to start with oauth and Twitter API for desktop apps without any Plugins? I am realy new to HTTPSocket and HTTPSecureSocket.

After many trys and readings i have this, but only get a 400 error:

Dim socket1 As New HTTPSecureSocket
Dim randomn As String
dim h As new HTTPSecureSocket
Dim timestamp As String
Dim keyer As String = “mykey”
Dim secret As String = “mysecret”
Dim newkey, encodedkey, encodedsecret As String
timestamp = h.get( “”, 5) //to get a timestamp

Dim encodedText as String
encodedText = EncodeBase64(newkey, 0)
encodedkey = EncodeBase64(keyer, 0)
encodedsecret = EncodeBase64(secret, 0)
newkey = EncodeBase64(encodedkey+":"+encodedsecret)
socket1.SetRequestHeader(“Host”, “”)
socket1.SetRequestHeader(“User-Agent”, “myappname”)
socket1.SetRequestHeader(“Authorization”, "Basic "+newkey)
socket1.SetRequestHeader(“Content-Type”, “application/x-www-form-urlencoded;charset=UTF-8”)
socket1.SetRequestHeader(“Content-Length”, “30”)
socket1.SetRequestHeader(“oauth_timestamp”, timestamp)
socket1.SetRequestContent(“grant_type=”, “client_credentials”)

TextArea1.Text = str(socket1.POST(“”, 30))
TextArea1.Text = str(socket1.HTTPStatusCode)

It is all in the Action off a button cause its testing. I hope someone can point me in the right direction.

For starters, doesn’t give you what you think. Use a Date instead.

Hi, normaly points to a php file on my own server wich gives me a time stamp, thats wrong?

You didn’t mention that. Rolling a Twitter client with oauth is tricky. I did this a couple years ago. Twitter had some step by step instructions with things you could verify at each step. It’s worth looking on their developer pages to see if they still have something like that.

[quote]You didn’t mention that.[/quote] Sorry. I looked a lomg time on the developers page, i think my biggest problem is to get the headers send correctly. But thanks for the anwser.


Ater a lot of work I am able to post tweets and images from my Xojo app… but the code is currently in no shape to share. A while back I started working on an example project that others could use but work that “pays” got in the way. If you are really interested I could restart that effort but it might take me a few weeks to get it done.

hi, thanks for the reply, but you shall not remove me the work, I do this purely as a hobby and want to learn, but I think this oauth think is too much for me :). meanwhile i found this code:, i will look at this, but i think realy thats too much for a beginner (like me).

p.s. arrrrg, it uses plugins

We ended up using Temboo for a project recently. Why try to support hundreds of different API’s in Xojo if someone else is willing to do it. Of course this may not be suitable for all projects or purposes.

Yes Phillip, this is right, but i will learn :). I think its even faster to use a service like Temboo, but than i can use plugins too. But now i get my header correctly. The header is build so for example (if anyone needs it):

Dim oAuthPayload As String
oAuthPayload = “OAuth "
oAuthPayload = oAuthPayload+“oauth_callback=”“oob””, "
oAuthPayload = oAuthPayload+“oauth_consumer_key=”""+consumerKey+""", "
oAuthPayload = oAuthPayload+“oauth_nonce=”""+nonce+""", "
oAuthPayload = oAuthPayload+“oauth_signature_method=”“HMAC-SHA1"”, "
oAuthPayload = oAuthPayload+“oauth_timestamp=”""+str(timestamp)+""", "
oAuthPayload = oAuthPayload+“oauth_version=”“1.0"”, "
oAuthPayload = oAuthPayload+“oauth_signature=”""+signature +""""

socket1.SetRequestHeader(“Authorization”, oAuthPayload)

This is from the praemusalpha i posted above.

During yesterday’s webinar Paul showed a oAuth Twitter example app… He said it would be posted soon…

arrrrg :slight_smile: no, nice to read