Jump to content

[UDF] Google oAuth 2.0 with AutoIt.


Ascer
 Share

Recommended Posts

  • 4 months later...
  • 2 months later...
On 1/10/2018 at 2:37 AM, dmob said:

It actually does; have used this UDF successfully, works as expected.

Post your code so we can help you debug...

Can you help me an examples about GCE (google compute engine) instance?

Link to comment
Share on other sites

On 10/2/2018 at 5:50 PM, PaulC said:

Can you help me an examples about GCE (google compute engine) instance?

I use this UDF is for authentication to Google services. Please refer to Google documentation for examples for the particular service you require. 

Link to comment
Share on other sites

  • 1 month later...
10 hours ago, x_bennY said:

i'm receiving this error: "+++ Line: 93, Func: aAuthGetAccessToken() -> Error durning reading $oHttp.ResponseText. Google must changed *json respond for this request."

I get the same error, but you should see all info is outputed in Console after that error :) So baiscly it works it just cant convert json format to array :)

Link to comment
Share on other sites

Google must changed *json respond for this request.

yes and no. The spaces is the problem. patch this:

Func _JsonValue($sString, $sStart, $sEnd, $iMode = 0, $bCase = False)
    $sString = StringStripWS($sString,8)
    $sStart = StringStripWS($sStart,8)
    $sEnd = StringStripWS($sEnd,8)

and that should take care of it.

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

On 17/11/2018 at 6:13 PM, argumentum said:

Then you get some kind of answer    =P

( be explicit )

I'm using @Ascer's code with the above tweak without problems.

mysteriously that message disappeared, but i can't get it working, it says that the message has been sent but it's not, this is the console output:

Message Sent Sucessfully!
MessageId: 
ThreadId: 
Sent message labels_ids:

image.png.0f3cf0c2a77cddc3e1ced7ea005c7192.png

 

 

Problem solved!

Several possible reasons:
1) Your trial period could have expired (if you use one). Check your status at admin.google.com
2) There is no email address that you use in FROM field created in your G Suite. So just create one.
3) Your email address is not a Gmail account. It is possible to be a Google Account but not a Gmail account (for example if you use the account for YouTube but have never enabled Gmail).
4) You may need to enable the Gmail feature or Gmail API access in your G Suite.

Edited by x_bennY
Link to comment
Share on other sites

  • 11 months later...

Does this still work? I tried getting an access code, but executing this code doesn't give me an URL with a code=

#include <oAuth.au3>

Local $sClientId = "167204758184-vpeues0uk6b0g4jrnv0ipq5fapoig2v8.apps.googleusercontent.com" 
Local $sRedirectUri = "http://localhost"

oAuth2GetAuthorizationCode($sClientId, $sRedirectUri)

(of course I changed it with my own ClientId).

Link to comment
Share on other sites

  • 1 year later...

Hi all,

Testing this now. It's hard to interpret the order of events

  •  Downloaded client_id.json  (OK, took me time to figure out how to do  that.)
  •  Got authorization after it opened up my default browser (after taking the client id & client secret from the downloaded client_id.json)
  •  The above authorization url included code=xxxxxxxxxx&scope=https://mail.google.com/ so  I did not use the scope in my authorization code.
  •  Next thing I tried was to ask Google about our Access Token and Refresh Token as shown in the instructions and I received the following result:
$oHttp.ResponseText = {
  "access_token": "xxxxxxxxxxx",
  "expires_in": 3599,
  "refresh_token": "1//0jHwqE this is a sample q8n5lgDCAK-",
  "scope": "https://mail.google.com/",
  "token_type": "Bearer"
}
+++ Something wrong with reading ResponseText.

Something wrong with response text but I did receive what seems to be a valid refresh token so i used that in a gmail sample and received the following:

$oHttp.ResponseText = {
  "access_token": "ya2 This is a sample kNY",
  "expires_in": 3599,
  "scope": "https://mail.google.com/",
  "token_type": "Bearer"
}
+++ Line: 34, Func: <none> -> Failed to get access token. Exiting..
>Exit code: 0    Time: 0.4095

So basically I'm stuck there at failing to get access token.  Not sure if it's the response text from the 1st code snippet I posted trying to obtain the access token or if someone how I should have some kind of code to keep obtaining the refresh token.  

Thanks for any ideas or tips.

Edited by NassauSky
Link to comment
Share on other sites

Thanks @argumentum

Took me a bit of time to understand the whole workflow.  I was going to use my own method to extract the json values because I wasn't sure exactly where your code belonged. 

In other words looking inside the oAuth.au3 file there was a function called _JsonValue and I just had to add your code:

    $sString = StringStripWS($sString,8)
    $sStart = StringStripWS($sStart,8)
    $sEnd = StringStripWS($sEnd,8)

to the top of the function and leave the rest of the code below it in the function intact.

I also realized I reauthorized so many times playing with this method, I wound up just automating the whole process and then received some great tokens to use in the gmail function.  Next and last step is somehow figuring out how to create a single function to use the tokens and log into a Google sheet and extract the value of a single cell.  That's going to be the hardest part of the code :-/

 

Thanks again.

Link to comment
Share on other sites

  • 1 year later...
On 4/25/2022 at 11:04 AM, kut0 said:

This UDF not work for me. Could you help me?

https://www.autoitscript.com/forum/topic/192391-udf-google-oauth-20-with-autoit/?do=findComment&comment=1409771

...not using this UDF myself but that was the solution back then. Also, paste the text instead of a pic. of the text as a rule of thumb.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...