Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21131

Replacing XML with JSON (Change of Twitter API 1.0 to 1.1)

$
0
0
Hello all!

I was hoping to get some direction from someone who is familiar with XML and JSON (and/or Twitter REST API 1.1).

I am only sending status updates to Twitter and not leveraging any other functionality

Currently, I simply created an XML string and send it to the appropriate URL (yes, and did all the Oauth authentication too), as follows: (Step 7 is what I am focusing upon) This code does work (or did until Twitter changed the API).
Code:


Sub send_message(TweetMsg As String, cOauth_consumer_key As String, _
    cOauth_consumer_secret As String, cOauth_token As String, cOTS As String)

Dim ColumnNum As Integer

'step 1: get all base data
cApi_method = "POST"
cApi_resource = "https://api.twitter.com/1.1/statuses/update.json"         

' Old URL for using XML... "http://api.twitter.com/1/statuses/update.xml"

cOauth_signature_method = "HMAC-SHA1"
cOauth_version = "1.0"
cStatus = URLEncode(TweetMsg)

'step 2: calculate nonce and timestamp
cOauth_nonce = get_oauth_nonce()
cOauth_timestamp = get_oauth_timestamp

'step 3: calculate base_string
cBase = get_basestring(cApi_method, cApi_resource, cOauth_consumer_key, cOauth_consumer_secret, cOauth_signature_method, cOauth_version, cOauth_token, cOTS, cOauth_nonce, cOauth_timestamp, cStatus)

'step 4: calculate composite signing key
cKey = cOauth_consumer_secret & "&" & cOTS

'step 5: calculate oauth_signature
cOauth_signature = get_oauth_signature(cBase, cKey)

'step 6: calcualte authorization header
cHeader = get_header(cApi_resource, cOauth_nonce, cOauth_signature_method, cOauth_timestamp, cOauth_consumer_key, cOauth_token, cOauth_signature, cOauth_version)

'****************** THIS IS WHAT I NEED TO CHANGE *****************
'step 7: send message                   

    Set xml = CreateObject("MSXML2.XMLHTTP")
    xml.Open cApi_method, cApi_resource & "?status=" & cStatus, False
    xml.setRequestHeader "Authorization", cHeader
    xml.Send
    tResult = xml.responseText
    Debug.Print tResult
    Set xml = Nothing


End Sub

I am not very familiar with JSON and would prefer to simply format the JSON string manually rather than integrate a JSON constructor/parser. (Again, I'm only sending a status (a.k.a "tweet"), and not using any extended functionality).

Any direction anyone may be able to provide, related to "Step 7" would be greatly appreciated (examples, resources, code that works :))

All the best!

Trip

Viewing all articles
Browse latest Browse all 21131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>