无法检索Google Oauth2的刷新令牌

时间:2015-05-13 11:42:08

标签: php curl google-api

我在php中使用以下代码来检索访问令牌:

  $url ="https://accounts.google.com/o/oauth2/token";
$fields = array(
   "client_id"=>"{your client id}",
   "client_secret"=>"{your client secret}",
   "refresh_token"=>"{your refresh token 1/.....}",
   "grant_type"=>"refresh_token"
);

$ch = curl_init($url);

//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_POST,count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//execute post
$lResponse_json = curl_exec($ch);

//close connection
curl_close($ch);

问题是我收到以下错误:

  

"错误" :" invalid_client",   " ERROR_DESCRIPTION" :"找不到OAuth客户端。"

我试过取消认证应用程序等仍无济于事。 有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

问题是我没有附上client_id等......在" "在数组中。 Curl没有正确发送请求。