首页 > google play获取refresh_token报错grant_type

google play获取refresh_token报错grant_type

代码如下(code、client_id、client_secret、redirect_uri都是正确的参数,下面只是代写):
$url = 'https://accounts.google.com/o/oauth2/token';
$data = array(
'grant_type'=>'authorization_code',
'code'=>'aaaa',
'client_id'=>'bbbb',
'client_secret'=>'cccc',
'redirect_uri'=>'http://dddd/callback.php'
);
$header = array("Content-Type:application/x-www-form-urlencoded;charset=UTF-8");
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
var_dump($result);
curl_close($ch);

打印出的result:
string(102) "{
"error" : "invalid_request",
"error_description" : "Required parameter is missing: grant_type"
}"

在网上已经查找很多资料,如header改为"Content-Type:application/x-www-form-urlencoded,要改为post方式,请求参数放在body里,但是仍然报错,求高人指点!!!

【热门文章】
【热门文章】