#include "WinHttp.au3" Opt("MustDeclareVars", 1) ; !!!Note that this example will fail because of invalid username and password!!! Global $sUserName = "test@gmail.com" Global $sPassword = "pass" Global $sDomain = "www.google.com" Global $sPage = "accounts/ClientLogin" ; Visit http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html for more informations Global $sAdditionalData = "accountType=GOOGLE&Email=" & $sUserName & "&Passwd=" & $sPassword & "&service=reader&source=Gulp-CalGulp-1.05" ; Initialize and get session handle Global $hOpen = _WinHttpOpen("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6") ; Get connection handle Global $hConnect = _WinHttpConnect($hOpen, $sDomain) _WinHttpSetOption($hConnect, $WINHTTP_OPTION_DISABLE_FEATURE, $WINHTTP_DISABLE_COOKIES) _WinHttpSetOption($hConnect,$WINHTTP_OPTION_DISABLE_FEATURE, $WINHTTP_DISABLE_REDIRECTS) ; Make a request Global $hRequest = _WinHttpOpenRequest($hConnect, "POST", $sPage, -1, -1, -1, $WINHTTP_FLAG_SECURE) ; Send it. Specify additional data to send too. This is required by the Google API: _WinHttpSendRequest($hRequest, "Content-Type: application/x-www-form-urlencoded", $sAdditionalData) ; Wait for the response _WinHttpReceiveResponse($hRequest) ; See what's returned Global $sReturned If _WinHttpQueryDataAvailable($hRequest) Then ; if there is data Do $sReturned &= _WinHttpReadData($hRequest) Until @error EndIf ; Close handles _WinHttpCloseHandle($hRequest) Local $aData = StringSplit($sReturned, @CRLF) Local $sSID = StringTrimLeft($aData[1], 4) Global $hRequest = _WinHttpOpenRequest($hConnect, "GET", "reader/api/0/token", -1, -1, -1) _WinHttpAddRequestHeaders($hRequest, "Cookie: SID=" & $sSID & "; domain=.google.com; path=/") _WinHttpSendRequest($hRequest, "Content-Type: application/x-www-form-urlencoded", "") _WinHttpReceiveResponse($hRequest) If _WinHttpQueryDataAvailable($hRequest) Then ; if there is data Do $sReturned &= _WinHttpReadData($hRequest) Until @error EndIf Global $sHeader = _WinHttpQueryHeaders($hRequest) _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) ; See what's returned MsgBox(0, "Returned", $sHeader) |