VBA-tools / VBA-Web

VBA-Web: Connect VBA, Excel, Access, and Office for Windows and Mac to web services and the web
http://vba-tools.github.io/VBA-Web/
MIT License
2.01k stars 494 forks source link

GoogleAuthenticator (bypass login process) #275

Open dmitrysilchenkogismart opened 7 years ago

dmitrysilchenkogismart commented 7 years ago

Could you help me, please?

I use GoogleAuthenticator but if I set Auth.ApiKey I have "Login Required" message response.

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}

If I don't use Auth.ApiKey (GoogleAuthOAuth2.ApiKey in my code) it works great but I have to login manually (via browser IE). I know it is called only on first request. But I need requests with "auto login". Please help me.


1. Sub google_adsense2()
2. 
3.     Dim Client As New WebClient
4.     Client.BaseUrl = "https://www.googleapis.com/adsense/v1.4"
5. 
6.     Dim Request As New WebRequest
7. 
8.     Dim Json As Object
9.     Dim Response As WebResponse
10. 
11.     Dim GoogleAuthOAuth2 As New GoogleAuthenticator
12. 
13.     Dim ClientId As String
14.     Dim ClientSecret As String
15.     Dim Username As String
16.     Dim Password As String
17. 
18. 
19.     ClientId = "************"
20.     ClientSecret = "************"
21. 
22. 
23.     GoogleAuthOAuth2.Setup ClientId, ClientSecret
24.     GoogleAuthOAuth2.AddScope "adsense.readonly"    ' -> https://www.googleapis.com/auth/adsense
25.     GoogleAuthOAuth2.AddScope "https://mail.google.com/"
26.     GoogleAuthOAuth2.ApiKey = "***********"
27. 
28.     Set Client.Authenticator = GoogleAuthOAuth2
29. 
30.     Request.Resource = "/adclients"
31.     
32. 
33.     Set Response = Client.Execute(Request)
34.     MsgBox Response.Content
35.     
36. End Sub

I found a awry way with token (I can save it after manual login and then put it before sending another requests) . How long will it work?

Thanks, you did really cool staff!

timhall commented 7 years ago

Hi @dmitrysilchenkogismart thanks for raising this issue (sorry for the delay getting to it). It should work ok with just an ApiKey, so I'll take a look into what the issue may be. I know that the authenticator was in need of an upgrade recently so it may have something to do with that.

dmitrysilchenkogismart commented 7 years ago

Hi, @timhall! I'm glad to see you! I am still suffering with authorization(((

dmitrysilchenkogismart commented 7 years ago

It still doesn't work (with v4.1.2).

pvitkovsky commented 7 years ago

Same here. Copied all of @dmitrysilchenkogismart code, "Login required" with Apikey not turned off, and "Automaton error" after IE dialog if Apikey is turned off.

glctesta commented 6 years ago

Same here. Do you have a solution?

ferrets6 commented 6 years ago

Found a solution for "Automaton error" after IE dialog. Don't know why, but according to this post on StackOverflow, simply using early binding and InternetExplorerMedium as object, it works.

I'm using your default GoogleAuthenticator.cls, changing line 132 and 135

Dim auth_IE As InternetExplorer Set auth_IE = New InternetExplorerMedium

P.S.: sorry, I'm very new in GitHub!

carlesserra commented 4 years ago

I am trying to use VBA-Tools to automatically insert and delete events in Google Calendar.

In order to fully automate the process, I need to bypass the Google log in but, as @dmitrysilchenkogismart, I get the same error, even after trying the solution provided by @ferrets6

Until I fix the problem, I will have to log in manually the first time each run, which is inconvenient.