【发布时间】:2015-09-27 18:45:37
【问题描述】:
我正在尝试使用下面的代码从 google api 获取访问令牌,
$grant = urlencode("urn:ietf:params:oauth:grant-type:jwt-bearer") . "&assertion=" . $jwtSign;
$postfields = array('Host' => 'www.googleapis.com', 'Content-Type' => 'application/x-www-form-urlencoded', 'POST' => '/oauth2/v3/token HTTP/1.1', 'grant_type' => $grant);
$headers = array(
"Content-Type: application/x-www-form-urlencoded"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.googleapis.com/oauth2/v3/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // On dev server only!
$result = curl_exec($ch);
但我说错了。请帮我看看有什么问题
{
"error": "invalid_request",
"error_description": "Required parameter is missing: grant_type"
}
【问题讨论】:
-
您将需要编写一些代码/努力自己编写代码。不幸的是,我们只提供代码帮助,而不是为您编写:)
标签: php curl google-api access-token