listi.net

Listi.net

             


Upload XML_it routine



Function XML_Auth(GetorPost, sURL, p1, p2, p3, p4)
'Dim cOauth_consumer_key, cOauth_consumer_secret, cOauth_signature_method, cOauth_version
'Dim cOauth_token, cOTS, cOauth_nonce, cOauth_timestamp, cBase, cKey, cOauth_signature, cHeader, tResult, cStatus
'Dim XML
'step 1: get all base data
Dim iRetry As Integer
Dim curSheet As String

'Get the row for the basedata
curSheet = ActiveSheet.Name

SelectSheet "Login" & gsSuffix
'sLookup = "=A1&A2"
r = FindLastRow(1)
sLookup = "=match(""" & Range("tusername") & """,'Login" & gsSuffix & "'!A:A,false)"

'application.evaluate doesn't work returns a error 2015 I
'think because the lenth of the returned string is 652 charactsw
Cells(1, 3).Formula = sLookup
lRow = Cells(1, 3)

cOauth_consumer_key = Cells(lRow, Range("consumer_key").Column) ' Sheets("basedata").Cells(4, 3)
cOauth_consumer_secret = Cells(lRow, Range("consumer_secret").Column) 'Sheets("basedata").Cells(5, 3)
cOauth_token = Cells(lRow, Range("access_token").Column) 'Sheets("basedata").Cells(8, 3)
cOTS = Cells(lRow, Range("access_token_secret").Column) 'Sheets("basedata").Cells(9, 3)


retry_it:
cApi_method = GetorPost 'Sheets("basedata").Cells(2, 3)
cApi_resource = sURL 'Sheets("basedata").Cells(3, 3)

cOauth_signature_method = Sheets("basedata").Cells(6, 3)
cOauth_version = Sheets("basedata").Cells(7, 3)


'cStatus = URLEncode(Sheets("basedata").Cells(12, 3))
If IsMissing(p2) Then
    p2 = ""
End If
If IsMissing(p1) Then
    p1 = ""
End If

p2 = URLEncode((p2))

'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, p1, p2) '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)
'--------------------------------------

'--------------------------------------
Set XML = CreateObject("MSXML2.XMLHTTP")
XML.Open cApi_method, cApi_resource & "?" & p1 & "=" & p2, False
'step 7: send message

'cApi_method = POST
'cApi_resource =http://api.twitter.com/1/statuses/update.xml
'               https://api.twitter.com/1/statuses/update.xml
XML.setRequestHeader "Authorization", cHeader
On Error Resume Next
XML.Send
If Err <> 0 Then
    iRetry = iRetry + 1
    If iRetry < 4 Then
        GoTo retry_it
    End If
    Popup Err & " " & Error
    Exit Function
End If

'If Err = -2146697205 Then
'End If
tResult = XML.responsetext
'Debug.Print tResult
'Cells(19, 2) = tResult
XML_Auth = tResult

Set XML = Nothing

Sheets(curSheet).Select


End Function



blog comments powered by Disqus
Home

Sign In
Sign Up

FAQ
About
Help
Contact Us
Terms and Conditions

Tweet List

Link to us