【发布时间】:2015-11-13 11:36:41
【问题描述】:
我正在尝试在我的网络应用中使用 google plus Api 登录。
我从https://developers.google.com/oauthplayground/https://developers.google.com/oauthplayground/搜索过它 我应用了它们。
当我请求 https://www.googleapis.com/oauth2/v3/token 时,它会返回
{ "error": "internal_failure", "error_description": "Unsupported content with type: multipart/form-data; boundary=----------------------------5dd1639f2986" }
我正在将我的代码 sn-ps 用于执行请求(作为客户端 ID 和秘密作为星号) 没看懂,希望大家帮忙
if(isset($_GET['code'])) {
// try to get an access token
$code = $_GET['code'];
$url = 'https://www.googleapis.com/oauth2/v3/token';
$params = array(
"code" => $code,
"client_id" => "************************",
"client_secret" => "************************",
"redirect_uri" => "http://localhost/googleplus/oauth2callback.php",
"grant_type" => "authorization_code"
);
$json=CallAPI('POST',$url,$params);
还有我的 CALLAPI 函数
function CallAPI($method, $url, $data = false)
{
$curl = curl_init();
switch ($method)
{
case "POST":
curl_setopt($curl, CURLOPT_POST, 1);
if ($data)
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
break;
case "PUT":
curl_setopt($curl, CURLOPT_PUT, 1);
break;
default:
if ($data){
$url = sprintf("%s?%s", $url, http_build_query($data));
echo $url;
}
}
// Optional Authentication:
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "username:password");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
【问题讨论】:
标签: api http google-api google-plus google-api-php-client