CrewXp Posted March 8, 2009 Share Posted March 8, 2009 I made. Er, well I THOUGHT I made a Function to get the source of a webpage that needed to be gotten through a Basic Authentication Request. I'm trying to connect to the Twitter API, which requires Basic Authentication. Normal Users can only get 100 queries per hour. When I'm authenticated, I can query as much as I want. Well I can only get 100 queries. So I assume that means my function is wrong..Do you see anything wrong?Twitter Info: http://apiwiki.twitter.com/REST+API+Docume...#Authenticationexpandcollapse popup#include <INet.au3> #include <WinINet.au3> $user="test" $pass="test" $cache=Http_Auth_GetSource("twitter.com","statuses/friends_timeline/22831657.rss",$username,$password,0);EXAMPLE TWITTER RSS Func Http_Auth_GetSource($hostname,$relative_location,$username,$password,$flag) $port_var=0 If StringInStr($hostname,":") Then $temp=StringSplit($hostname,":") $port_var=Int($temp[2]) $hostname=StringReplace($hostname,":"&$port_var,"") EndIf Global $hInternetOpen, $hInternetConnect, $hHttpOpenRequest, $hHttpSendRequest Global $iStartup, $iShutdown, $iInternetAttemptConnect ; start WinINet libary $iStartup = _WinINet_Startup() ; attempt a connection $iInternetAttemptConnect = _WinINet_InternetAttemptConnect() ; successful attempt If $iInternetAttemptConnect Then ; open a connection $hInternetOpen = _WinINet_InternetOpen("Mozilla/5.0 Firefox/3.0.1", $INTERNET_OPEN_TYPE_DIRECT, 0, Default, Default) ConsoleWriteLog("_WinINet_InternetOpen", @error, @extended, $hInternetOpen) ; connect to a web server $hInternetConnect = _WinINet_InternetConnect($hInternetOpen, $INTERNET_SERVICE_HTTP, $hostname, $port_var, 0, $username,$password, 0) ConsoleWriteLog("_WinINet_InternetConnect", @error, @extended, $hInternetConnect) ; set up a request a file $hHttpOpenRequest = _WinINet_HttpOpenRequest($hInternetConnect, "POST", $relative_location, $INTERNET_FLAG_RELOAD, "HTTP/1.1", Default, Default, 0) ConsoleWriteLog("_WinINet_HttpOpenRequest", @error, @extended, $hHttpOpenRequest) ; send the request to the http server $hHttpSendRequest = _WinINet_HttpSendRequest($hHttpOpenRequest, Default, Default) ConsoleWriteLog("_WinINet_HttpSendRequest", @error, @extended, $hHttpSendRequest) ; get the file size - NOT NEEDED FOR THIS SCRIPT $iLength = Default $avLength = _WinINet_HttpQueryInfo($hHttpOpenRequest, BitOR($HTTP_QUERY_CONTENT_LENGTH, $HTTP_QUERY_FLAG_NUMBER), 0) If Not @error Then ; retrieve content length $iLength = DllStructGetData(DllStructCreate("dword", DllStructGetPtr($avLength[0])), 1) ConsoleWrite("--> Length of file: " & $iLength & " bytes" & @CRLF) EndIf ; download the file into $vReceived (binary data) $fCompleted = False $iReceivedSize = 0 $vReceived = Binary("") Do $vReceived &= _WinINet_InternetReadFile($hHttpOpenRequest, 1024) $fCompleted = @error Or Not @extended Until $fCompleted return $vReceived Else Msgbox(0,"Twitter Checker","No Internet Signal Detected, Exiting...") EndIf ; end WinINet library $iShutdown = _WinINet_Shutdown() ConsoleWrite("_WinINet_Shutdown::"&@error&@extended&$iShutdown) EndFunc Link to comment Share on other sites More sharing options...
CrewXp Posted March 9, 2009 Author Share Posted March 9, 2009 is it correct? If not, i think its something wrong with hInternetConnect Link to comment Share on other sites More sharing options...
/dev/null Posted March 9, 2009 Share Posted March 9, 2009 is it correct? If not, i think its something wrong with hInternetConnectyou are defining:$user="test"$pass="test"But then you pass the undefined variables "$username" and "$password" to the function. $cache=Http_Auth_GetSource("twitter.com","statuses/friends_timeline/22831657.rss",$username,$password,0);EXAMPLE TWITTER RSSMight that cause your problem?CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
CrewXp Posted March 9, 2009 Author Share Posted March 9, 2009 you are defining:$user="test"$pass="test"But then you pass the undefined variables "$username" and "$password" to the function. $cache=Http_Auth_GetSource("twitter.com","statuses/friends_timeline/22831657.rss",$username,$password,0);EXAMPLE TWITTER RSSMight that cause your problem?CheersKurtThanks Kurt for the comment. But naw, that's not the problem. I pseudo'coded the example code for forum users so they could better understand it and keep their patience level and not close out the topic I found it actually. Turns out it was working Normal users can only request 100 times before getting blocked, so when I wrote my code I hard-coded itself to change usernames it authenticates with after 100 tries (method fails because they block by ip too). I changed the code once I was whitelisted, but somehow it was un-commented and returned to my code. Thanks. Problem solved. Feel free to use the http basic auth, for whoever wants it. Link to comment Share on other sites More sharing options...
seangriffin Posted July 2, 2010 Share Posted July 2, 2010 Thanks Kurt for the comment. But naw, that's not the problem. I pseudo'coded the example code for forum users so they could better understand it and keep their patience level and not close out the topic I found it actually. Turns out it was working Normal users can only request 100 times before getting blocked, so when I wrote my code I hard-coded itself to change usernames it authenticates with after 100 tries (method fails because they block by ip too). I changed the code once I was whitelisted, but somehow it was un-commented and returned to my code. Thanks. Problem solved. Feel free to use the http basic auth, for whoever wants it. For OAuth, you can use my Twitter UDF (http://www.autoitscript.com/forum/index.php?showtopic=116600) Cheers, Sean. See my other UDFs: Chrome UDF - Automate Chrome | SAP UDF - Automate SAP | Java UDF - Automate Java Applications & Applets | Tesseract (OCR) UDF - Capture text from applications, controls and the desktop | Textract (OCR) UDF - Capture text from applications and controls | FileSystemMonitor UDF - File, Folder, Drive and Shell Monitoring | VLC (Media Player) UDF - Creating and controlling a VLC control in AutoIT | Google Maps UDF - Creating and controlling Google Maps (inc. GE) in AutoIT | SAPIListBox (Speech Recognition) UDF - Speech Recognition via the Microsoft Speech (SAPI) ListBox | eBay UDF - Automate eBay using the eBay API | ChildProc (Parallel Processing) UDF - Parallel processing functions for AutoIT | HyperCam (Screen Recording) UDF - Automate the HyperCam screen recorder | Twitter UDF - Automate Twitter using OAuth and the Twitter API | cURL UDF - a UDF for transferring data with URL syntax See my other Tools: Rapid Menu Writer - Add menus to DVDs in seconds | TV Player - Automates the process of playing videos on an external TV / Monitor | Rapid Video Converter - A tool for resizing and reformatting videos | [topic130531]Rapid DVD Creator - Convert videos to DVD fast and for free | ZapPF - A tool for killing processes and recycling files | Sean's eBay Bargain Hunter - Find last minute bargains in eBay using AutoIT | Sean's GUI Inspector - A scripting tool for querying GUIs | TransLink Journey Planner with maps - Incorporating Google Maps into an Australian Journey Planner | Automate Qt and QWidgets | Brisbane City Council Event Viewer - See what's going on in Brisbane, Australia Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now