OAuth 2.0 en php usando curl
Necesito obtener mi access_token y refresh_token para que OAuth 2.0 acceda a las API de Google, el script php a continuación debería devolver un json con access_token, refresh_token de esta manera:
{
"access_token" : "####",
"token_type" : "Bearer",
"expires_in" : 3600,
"refresh_token" : "####"
}
pero, el script php me devuelve solo este mensaje de error:
{
"error" : "invalid_request",
"error_description" : "Client must specify either client_id or client_assertion, not both"
}
Intenté eliminar client_secret / client_id y usar solo client_id / client_secret, pero aún obtengo el mismo error.
Script PHP$client_id = '###.apps.googleusercontent.com';
$redirect_uri = 'http://localhost/phpConnectToDB/csv/refreshFusionTable.php';
$client_secret = '###';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://accounts.google.com/o/oauth2/token");
$code = $_REQUEST['code'];
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'code' => $code,
'client_id' => $clientID,
'client_secret' => $clientSecret,
'redirect_uri' => $redirect_uri,
'grant_type' => 'authorization_code'
));
$data = curl_exec($ch);
var_dump($data);
Aunque curl en cmd funciona y me devuelve el token de acceso y actualización sin ningún error.
curl --data "code=###&client_id=###.apps.googleusercontent.com&client_secret=###&redirect_uri=http://localhost/phpConnectToDB/csv/refreshFusionTable.php&am,p;grant_type=authorization_code" https://accounts.google.com/o/oauth2/token
No entiendo por qué me sale el error de esquema faltante, aunque el script .php existe y se encuentra en la ruta dada. Usted me podría ayudar por favor ?
EDITARProblema con "Valor de parámetro no válido para redirect_uri: Falta esquema" resuelto, acabo de reemplazar 'redirect_uri' => urlencode ($ redirect_uri), con este 'redirect_uri' => $ redirect_uri, en CURLOPT_POSTFIELDS.