No hay soporte ni la mas minima ayuda para esta API de Google en cuanto a la arquitectura REST.
Me doy por vencido. Aqui dejo el codigo para autenticacion OAuth2.
Estos pasos son practicamente los mismos para cualquier API. Difiere muy poco una de otra.
De hecho, se puede utilizar para realizar autenticacion de usuario muy robustas, como por ejemplo Okta.
La pagina del lado servidor es basica. Solo recoje el code que envia Google y lo imprime en el cuerpo.
En la linea strData = IE.Document.Body.innerhtml, lo tomo para hacer la solicitud del token.
A continuacion, contenido de la PHP:
<?php
header('Access-Control-Allow-Origin: *');
if($_REQUEST){
$auth_code = $_REQUEST['code'];
echo $auth_code;
}
?>
Option Compare Database
'referencias necesarias
'Microsoft Internet Control
'Microsoft Scripting Runtime
Dim MyCall As Object, objHeaders As Object
Dim WithEvents IE As SHDocVw.InternetExplorer
Dim redirect_uri As String, client_id As String, secret_id As String, scope As String, strData As String, strURL As String
Private Sub Command0_Click()
'On Error GoTo lbl_err
Dim code As String
If IsObject(IE) Then
Set IE = Nothing
End If
Set IE = CreateObject("InternetExplorer.Application")
strURL = "https://accounts.google.com/o/oauth2/v2/auth?client_id=" & client_id & "&response_type=code&scope=openid%20email&redirect_uri=" & redirect_uri
IE.Navigate strURL
IE.Visible = True
Do While IE.Busy
Me.Caption = "Please, wait..."
Loop
lbl_exit:
Exit Sub
lbl_err:
Debug.Print Err.Number
Resume lbl_exit
End Sub
Private Sub Form_Open(Cancel As Integer)
redirect_uri = "http://squarelab.solutions/contacts/endpoint.php"
client_id = "#################################.apps.googleusercontent.com"
secret_id = "###########################"
End Sub
Private Sub IE_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
Debug.Print URL
If InStr(1, URL, "http://squarelab.solutions/contacts/endpoint.php?code=", vbTextCompare) > 0 Then
strData = IE.Document.Body.innerhtml
IE.Visible = False
IE.Quit
Set IE = Nothing
'solicitar el token con la autorizacion (code) recibida. este es el paso 4
' descrito en la URL: https://docs.connect.squareup.com/api/oauth/?q=token#post-token
'Debug.Print getToken(strData)
getToken (strData)
End If
End Sub
Function getToken(code As String) As String
strURL = "https://accounts.google.com/o/oauth2/token"
strData = "code=" & code & "&client_id=" & client_id & "&client_secret=" & secret_id & "&redirect_uri=" & redirect_uri & "&grant_type=authorization_code"
'lleno mis headers necesarios
Set objHeaders = New Scripting.Dictionary
objHeaders.Add "Content-Type", "application/x-www-form-urlencoded"
resp = myRequest(strURL, objHeaders, "POST", strData)
Debug.Print resp
'Set JSONresp = JSONConverter.ParseJson(resp)
'If JSONresp.Exists("access_token") Then
' access_token = JSONresp("access_token")
'contact_list access_token, CStr(code)
' MsgBox access_token
'Else
' MsgBox "No se recibio un token"
'End If
End Function
Function myRequest(strURL As String, ByRef objHeader, strAction As String, data As String) As String
Set MyCall = CreateObject("WINHTTP.WinHTTPRequest.5.1")
With MyCall
.Open strAction, strURL, True ' true es modo asincrono
If IsObject(objHeader) And objHeader.Count > 0 Then
For Each itm In objHeader.Keys
.setRequestHeader itm, objHeader.Item(itm)
Next
End If
.send (data)
.waitForResponse
myRequest = .responseText
End With
Set MyCall = Nothing
Set objHeaders = Nothing
End Function