Php 无效的授权类型-oauth 2.0-正在获取令牌

Php 无效的授权类型-oauth 2.0-正在获取令牌,php,curl,oauth,oauth-2.0,oauth2client,Php,Curl,Oauth,Oauth 2.0,Oauth2client,我已经为下面的代码挣扎了一段时间。我得到以下错误:{“error”:“invalid_request”,“error_description”:“invalid grant type”} 我正在编写的API的更多文档如下: 来自 将数组传递给CURLOPT_POSTFIELDS将把数据编码为多部分/表单数据,而传递URL编码的字符串将把数据编码为application/x-www-form-urlencoded 对于您正在使用的API,必须使用application/x-www-form-url

我已经为下面的代码挣扎了一段时间。我得到以下错误:{“error”:“invalid_request”,“error_description”:“invalid grant type”}

我正在编写的API的更多文档如下:

来自

将数组传递给CURLOPT_POSTFIELDS将把数据编码为多部分/表单数据,而传递URL编码的字符串将把数据编码为application/x-www-form-urlencoded

对于您正在使用的API,必须使用
application/x-www-form-urlencoded

<?php

$curl = curl_init();

$postFields = array(
  'code'          => 'code',
  'grant_type'    => 'authorization_code',
  'redirect_uri'  => 'http://website.com/foursquare2.php',
  'client_id'     => 'f8de67be8dc84e449203fcdd4XXXXXXX',
  'client_secret' => 'HS5ZeIVsKW0/qqiO9/XcdeWqnF8vtzQrpY8gcdrxg0BXNZXXXXXXX',
  );

curl_setopt_array(
    $curl, array(
        CURLOPT_URL => "https://id.shoeboxed.com/oauth/token",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_SSL_VERIFYPEER => false, 
        CURLOPT_POST => 1,  
        CURLOPT_POSTFIELDS => http_build_query($postFields),
    )
);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response;
}

您设置了
应用程序/x-www-form-urlencoded
(这是正确的),但您的身体是用JSON编码的。只要改变你的身体,它就会很好地工作。我到底应该编码什么?只是重定向uri?我试过了,但也犯了同样的错误。我尝试对所有http web地址进行编码,并为发布地址获取一个http not found地址。我愿意为你的帮助付费(最好)或者再次指导我。不,整个身体:
CURLOPT\u POSTFIELDS=>http\u build\u query(['code'=>'[code]“,”授权类型“=>”授权代码“,”重定向uri“=>”http://website.com/foursquare2.php“,”客户id“=>”f8de67be8dc84e449203fcdd4XXXXXXX“,”客户机密“=>”HS5ZeIVsKW0/qqiO9/XcdeWqnF8vtzQrpY8gcdrxg0BXNZXXXXXXX'])
<?php

$curl = curl_init();

$postFields = array(
  'code'          => 'code',
  'grant_type'    => 'authorization_code',
  'redirect_uri'  => 'http://website.com/foursquare2.php',
  'client_id'     => 'f8de67be8dc84e449203fcdd4XXXXXXX',
  'client_secret' => 'HS5ZeIVsKW0/qqiO9/XcdeWqnF8vtzQrpY8gcdrxg0BXNZXXXXXXX',
  );

curl_setopt_array(
    $curl, array(
        CURLOPT_URL => "https://id.shoeboxed.com/oauth/token",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_SSL_VERIFYPEER => false, 
        CURLOPT_POST => 1,  
        CURLOPT_POSTFIELDS => http_build_query($postFields),
    )
);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response;
}