类型不受支持的内容:Google中的multipart/form-data以及api oauth2 [英] Unsupported content with type: multipart/form-data in google plus api oauth2

查看:116
本文介绍了类型不受支持的内容:Google中的multipart/form-data以及api oauth2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的Web应用程序中使用google plus Api登录.

I am trying to sign in with google plus Api in my web app.

我在 https://developers上进行了搜索. google.com/oauthplayground/https://developers.google.com/oauthplayground/ 然后我应用了它们

I searched on it from https://developers.google.com/oauthplayground/https://developers.google.com/oauthplayground/ and I applied them.

当我请求 https://www.googleapis.com/oauth2/v3/token ,它返回

{ "error": "internal_failure", "error_description": "Unsupported content with type: multipart/form-data; boundary=----------------------------5dd1639f2986" }

我正在放置正在执行请求的代码段(作为客户端ID和作为星号的秘密) 我不明白,也许您可​​以帮忙.

I am putting my code snippets which are doing the request (as client id and secret as star) I dont understand it, maybe you can help.

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函数

and my CALLAPI function

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;
}

推荐答案

您的请求是正确的但缺少一些内容 内容类型不是multipart/form-data应该改为application/x-www-form-urlencoded

You request is correct but missing something the content type is not multipart/form-data should be application/x-www-form-urlencoded instead

这篇关于类型不受支持的内容:Google中的multipart/form-data以及api oauth2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆