oAuth 2.0 is security system implemented by Google a few years ago. You are able to connect into your Google accounts and manage documents. In this UDF i show you how to pass first authorization process., this allow you to automate most of functions using API interface. 2. Requirements.
Google account. oAuth.au3 Download 3. Possibilities
;============================================================================================================ ; Date: 2018-02-10, 14:21 ; ; Description: UDF for authorize your app with oAuth 2.0 Google. ; ; Function(s): ; oAuth2GetAuthorizationCode() -> Get Code for "grant". ; oAuth2GetAccessToken() -> Get "access_token" and "refresh_token" first time. ; oAuth2RefreshAccessToken() -> Get current "access_token" using "refresh_token". ; ; Author(s): Ascer ;============================================================================================================ 4. Enable your Google API.
4.1. Video Tutorial not mine!
YouTube 4.2 Screenshots from authorization process (Polish language)
Go to https://console.developers.google.com/apis/dashboard and accept current rules.
Next create an new project
Enter name of you new project and click Create
Google will working now, please wait until finish. Next go to enable your API interface, we make if for Google
Take "Gmail" in search input and after click in found result.
Click Enable interface, Google will working now.
Create your login credentials
Select Windows Interface (combobox), User credentials (radio) and click button what is need bla bla
Type name of a new client id for oAuth 2.0 and click Create a new Client ID.
Next configure screen aplication, type some name and click Next. Google will working now.
Last step on this website is download source with your credentials in *Json format.
Now you received a file named client_id.json, it's how it look in Sublime Text:
Now we need to call a some function to get access code.
#include <oAuth.au3> Local $sClientId = "167204758184-vpeues0uk6b0g4jrnv0ipq5fapoig2v8.apps.googleusercontent.com" Local $sRedirectUri = "http://localhost" oAuth2GetAuthorizationCode($sClientId, $sRedirectUri)
Function will execute default browser for ask you to permission.
Next Google ask you to permission for access to your personal details by application Autoit
Now you can thing is something wrong but all is ok, you need to copy all after code= . It your access code.
Let's now ask Google about our Access Token and Refresh Token
#include <oAuth.au3> Local $sClientId = "167204758184-vpeues0uk6b0g4jrnv0ipq5fapoig2v8.apps.googleusercontent.com" Local $sClientSecret = "cWalvFr3WxiE6cjUkdmKEPo8" Local $sAuthorizationCode = "4/AAAPXJOZ-Tz0s6mrx7JbV6nthXSfcxaszFh_aH0azVqHkSHkfiwE8uamcabn4eMbEWg1eAuUw7AU0PQ0XeWUFRo#" Local $sRedirectUri = "http://localhost" Local $aRet = oAuth2GetAccessToken($sClientId, $sClientSecret, $sAuthorizationCode, $sRedirectUri) If Ubound($aRet) <> 4 then ConsoleWrite("+++ Something wrong with reading ResponseText." & @CRLF) Exit EndIf ConsoleWrite("Successfully received data from Google." & @CRLF) ConsoleWrite("access_token: " & $aRet & @CRLF) ConsoleWrite("expires_in: " & $aRet & @CRLF) ConsoleWrite("refresh_token: " & $aRet & @CRLF) ConsoleWrite("token_type: " & $aRet & @CRLF)
Important! When you received error 400 and output says: Invalid grant it means that your previous generated access_code lost validity and you need to generate new calling previus code. When everything is fine you should received a 4 informations about your: access_token, expires_in, refresh_token and token_type. Access_Token time is a little short so you need to know fuction possible to refresh it (tell Google that he should generate a new Token for you)
#include <oAuth.au3> Local $sRefreshToken = "1/ba8JpW7TjQH3-UI1BvPaXhSf-oTQ4BmZAbBfhcKgKfY" Local $sClientId = "167204758184-vpeues0uk6b0g4jrnv0ipq5fapoig2v8.apps.googleusercontent.com" Local $sClientSecret = "cWalvFr3WxiE6cjUkdmKEPo8" Local $sRedirectUri = "http://localhost" Local $aRet = oAuth2RefreshAccessToken($sRefreshToken, $sClientId, $sClientSecret) If Ubound($aRet) <> 3 then ConsoleWrite("+++ Something wrong with reading ResponseText." & @CRLF) Exit EndIf ConsoleWrite("Successfully received data from Google." & @CRLF) ConsoleWrite("access_token: " & $aRet & @CRLF) ConsoleWrite("expires_in: " & $aRet & @CRLF) ConsoleWrite("token_type: " & $aRet & @CRLF)
6. Finish words
If you followed all this above steps im sure that you received all informations required for coding your Google API (Gmail, Dropbox, YouTube, Calender etc. See next thread: [UDF] Gmail API - Email automation with AutoIt!
Perform a simple google search!
The script below works fine until fill the google form!
What I can't find is how to submit the form, tried a couple of ways and none of them worked.
#include <IE.au3> $oIE = _IECreate ("www.google.com") $o_form = _IEFormGetObjByName ($oIE, "f") $o_login = _IEFormElementGetObjByName ($o_form, "q") $username = "80251369" _IEFormElementSetValue ($o_login, $username) $o_numer = _IEGetObjByName($o_form, "btnK") _IEAction ($o_numer, "click")
The code runs without any problem.
I don't know how to proceed!
Thanks in advance!
Dear master, hello,
I got the speech API from Google. But I could not find how to use. Could you help me with a simple example?
I am struggling to find a way to force a ControlClick on a particular hidden element within a Google Slides window. Using Au3Info doesn't work as the hidden text won't appear when attempting to gather the data. Using inspect element will show the class/title of the button, but using the class in the ControlClick function doesn't seem to do anything. Since this script is going to be running on multiple machines with different resolutions, MouseClick isn't a good option either. Can someone help me figure out how to click this full screen button?
One more note - It says "Ctrl + Shift + F" for full screen, however sending that combo doesn't work - nor does actually using those keys on the keyboard. Possible conflict with AutoIT hotkeys?
Here's some sample code / screenshots to help:
ControlClick($Title, "", "[CLASS:punch-viewer-icon punch-viewer-full-screen goog-inline-block]")
I'm trying to translate with google translator but not able to translate my text file from Russian to English and my output saved in text file is 0 instead of any translated text.
I'm using a text file which contains 5 lines of Russian language and I want to translate it into English language and want to save it in other text file translated.txt but I'm not able to let it happen.
Please help me how can I make this possible same code was working several months ago but not now especially don't know what's going wrong with my code of google translator.
Here are my codes
#RequireAdmin #include <IE.au3> #include <String.au3> #include <Array.au3> ProcessClose ( 'iexplore.exe') $File1 = @ScriptDir & "\kat01.txt" $txt = FileRead($File1) ;-------------------------------Translation Started------------------------- Local $tag="* # * # *" Local $oIE=_IECreate("https://translate.google.com/#ru/en", 1, 1) Local $oForm=_IEFormGetCollection($oIE,0) Local $oQuery=_IEGetObjByName($oForm,"text") _IEFormElementSetValue($oQuery, $tag & @CR & $txt & @CR & $tag) _IEFormSubmit($oForm) _IELoadWait($oIE) Local $oText=_IEGetObjById($oIE,"gt-res-data") $lines=StringSplit(_IEPropertyGet($oText,"innerText"),@CRLF,1) ;_IEQuit($oIE) _ArrayDelete($lines,_ArraySearch($lines,$tag,1,0,0,1,0) & "-" & $lines) _ArrayDelete($lines,"1-" & _ArraySearch($lines,$tag,1,0,0,1,1)) $lines=UBound($lines)-1 _ArrayDisplay($lines) Local $sFilePath = @ScriptDir & "\Translated.txt" _FileWriteFromArray($sFilePath, $lines, 1)