Code: Select all
ClientId := "xxxxxxxxxxxxxx.apps.googleusercontent.com"
ClientSecret := "xxxxxxxxxxxxxxx"
RedirectUri := "urn:ietf:wg:oauth:2.0:oob"
scope := "https www.googleapis.com /auth/drive.file"
FirstUrl := "https accounts.google.com /o/oauth2/auth?redirect_uri="UriEncode(RedirectUri) "&response_type=code&client_id=" ClientId "&scope=" UriEncode(scope) "&clientSecret=" ClientSecret "&approval_prompt=force"
wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := True
wb.Navigate(FirstUrl)
while wb.ReadyState!=4 || wb.document.readyState!="complete" || wb.busy
Sleep 100
UriEncode(Uri)
{
VarSetCapacity(Var, StrPut(Uri, "UTF-8"), 0)
StrPut(Uri, &Var, "UTF-8")
f := A_FormatInteger
SetFormat, IntegerFast, H
While Code := NumGet(Var, A_Index - 1, "UChar")
If (Code >= 0x30 && Code <= 0x39 ; 0-9
|| Code >= 0x41 && Code <= 0x5A ; A-Z
|| Code >= 0x61 && Code <= 0x7A) ; a-z
Res .= Chr(Code)
Else
Res .= "%" . SubStr(Code + 0x100, -1)
SetFormat, IntegerFast, %f%
Return, Res
}
Code: Select all
ClientId := "xxxxxxxxxxx.apps.googleusercontent.com"
ClientSecret := "xxxxxxxxxxxxxx"
AuthorizationCode := "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
RedirectUri := "urn:ietf:wg:oauth:2.0:oob"
Request := "grant_type=authorization_code&code=" AuthorizationCode "&redirect_uri=" UriEncode(RedirectUri) "&client_id=" ClientId "&client_secret=" ClientSecret
WinHTTP := ComObjCreate("WinHTTP.WinHTTPRequest.5.1")
WinHTTP.Open("POST", "https accounts.google.com /o/oauth2/token",true)
WinHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
WinHTTP.Send(Request)
WinHTTP.WaitForResponse()
msgbox % clipboard := WinHTTP.ResponseText
Code: Select all
access_token := "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
CreateFormData(postData, hdr_ContentType, objParam)
WinHTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WinHTTP.Open("POST", "https www.googleapis.com /upload/drive/v3/files",true)
WinHTTP.SetRequestHeader("Content-Type", hdr_ContentType)
WinHTTP.SetRequestHeader("Authorization", "Bearer " access_token)
WinHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")
WinHTTP.Option(6) := False ; No auto redirect
WinHTTP.Send(postData)
WinHTTP.WaitForResponse()
MsgBox % WinHTTP.ResponseText
Code: Select all
ClientId := "xxxxxxxxxxxxxx7.apps.googleusercontent.com"
ClientSecret := "xxxxxxxxxxxxxxxxxxxxxxxxxx"
RefreshToken := "1//0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxrXc"
Request := "refresh_token=" RefreshToken "&client_id=" ClientId "&client_secret=" ClientSecret "&grant_type=refresh_token"
WinHTTP := ComObjCreate("WinHTTP.WinHTTPRequest.5.1")
WinHTTP.Open("POST", "https accounts.google.com /o/oauth2/token", true)
WinHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
WinHTTP.Send(Request)
WinHTTP.WaitForResponse()
msgbox % clipboard := WinHTTP.ResponseText
Thank you.