My 3 Twitter functions use basic Auth and I want to port them to oAuth ASAP
I want to use PIN access for my app I'm not very good at HTTP programming, so any help is appreciated ============================================= #include-once #include <Base64.au3> Func _TwitterPost($sTweet, $sTwitId, $sTwitPw, ByRef $LimitExceeded) Local $oTweet = _CreateMSXMLObj() If $oTweet = 0 Then SetError(1, 1, 0) Local $sTwitUrl = "http://twitter.com/statuses/update.xml" Local $sLogin = _Base64Encode($sTwitId & ":" & $sTwitPw) Local $sUpdate = "status=" & _UrlEncode(StringLeft($sTweet, 140)) $oTweet.Open("POST", $sTwitUrl, False) $oTweet.setRequestHeader("Content-Type", "application/x-www-form- urlencoded") $oTweet.setRequestHeader("Authorization", "Basic " & $sLogin) $oTweet.send($sUpdate) If $oTweet.status <> 200 Then SetError(2, 2, 0) if $oTweet.status =401 then MsgBox(0,"Username/password","Check your Username or Password for user:"&$sTwitId,5); if $oTweet.status =403 then $LimitExceeded=True; If StringInStr($oTweet, "created_at") = 0 Then SetError(3, 3, 0) Return 1 EndFunc Func _TwitterFollow($FollowID, $sTwitId, $sTwitPw, ByRef $LimitExceeded) Local $oTweet = _CreateMSXMLObj() If $oTweet = 0 Then SetError(1, 1, 0) Local $sTwitUrl = StringFormat("http://api.twitter.com/1/ friendships/create/%s.xml", $FollowID); Local $sLogin = _Base64Encode($sTwitId & ":" & $sTwitPw) Local $sUpdate = ""; $oTweet.Open("POST", $sTwitUrl, False) $oTweet.setRequestHeader("Content-Type", "application/x-www-form- urlencoded") $oTweet.setRequestHeader("Authorization", "Basic " & $sLogin) $oTweet.send($sUpdate) If $oTweet.status <> 200 Then SetError(2, 2, 0) if $oTweet.status =401 then MsgBox(0,"Username/password","Check your Username or Password for user:"&$sTwitId,5); if $oTweet.status =403 then $LimitExceeded=True; If StringInStr($oTweet, "created_at") = 0 Then SetError(3, 3, 0) Return 1 EndFunc Func _TwitterUnFollow($UnFollowID, $sTwitId, $sTwitPw, ByRef $LimitExceeded) Local $oTweet = _CreateMSXMLObj() If $oTweet = 0 Then SetError(1, 1, 0) Local $sTwitUrl = StringFormat("http://api.twitter.com/1/ friendships/destroy/%s.xml", $UnFollowID); Local $sLogin = _Base64Encode($sTwitId & ":" & $sTwitPw) Local $sUpdate = ""; $oTweet.Open("POST", $sTwitUrl, False) $oTweet.setRequestHeader("Content-Type", "application/x-www-form- urlencoded") $oTweet.setRequestHeader("Authorization", "Basic " & $sLogin) $oTweet.send($sUpdate) If $oTweet.status <> 200 Then SetError(2, 2, 0) if $oTweet.status =401 then MsgBox(0,"Username/password","Check your Username or Password for user:"&$sTwitId,5); if $oTweet.status =403 then $LimitExceeded=True; If StringInStr($oTweet, "created_at") = 0 Then SetError(3, 3, 0) Return 1 EndFunc ; Ganked and modified from: http://www.autoitscript.com/forum/index.php?showtopic=77155 Func _CreateMSXMLObj() Local $xmlObj = ObjCreate("Msxml2.XMLHTTP.6.0") If IsObj($xmlObj) Then Return $xmlObj $xmlObj = ObjCreate("Msxml2.XMLHTTP.3.0") If IsObj($xmlObj) Then Return $xmlObj $xmlObj = ObjCreate("Msxml2.XMLHTTP") If IsObj($xmlObj) Then Return $xmlObj $xmlObj = ObjCreate("Microsoft.XMLHTTP") If IsObj($xmlObj) Then Return $xmlObj Return 0 EndFunc Func _UrlEncode($sData) $sData = StringReplace($sData, "%", "%25") $sData = StringReplace($sData, "&", "%26") $sData = StringReplace($sData, "<", "%3C") $sData = StringReplace($sData, ">", "%3E") $sData = StringReplace($sData, "~", "%7E") $sData = StringReplace($sData, " ", "%20") $sData = StringReplace($sData, @CRLF, "\r\n") Return $sData EndFunc Func _UrlDecode($sData) $sData = StringReplace($sData, "%3C", "<") $sData = StringReplace($sData, "%3E", ">") $sData = StringReplace($sData, "%7E", "~") $sData = StringReplace($sData, "%20", " ") $sData = StringReplace($sData, "%26", "&") $sData = StringReplace($sData, "%25", "%") $sData = StringReplace($sData, "<br>", @CRLF) Return $sData EndFunc Attached File(s) TwitterAPI.au3 (3.84K) Number of downloads: 3 This post has been edited by tobject: 25 July 2010 - 02:54 PM Report Back to top of the page up there ^ MultiQuote Reply Edit