【发布时间】:2018-09-30 16:01:34
【问题描述】:
我正在尝试使用 oAuth 2.0 将授权代码(位于此页面的 url 中)交换为访问令牌。
我正在运行以下 php 代码并收到错误(http 错误 500)。
我无法弄清楚以下代码有什么问题。我已经删除了实际的客户 ID,等等-它在那里显示代码:
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://id.shoeboxed.com/oauth/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\"grant_type\":\"authorization_code\",\"client_id\": \"f8de67be8dc84e449203fcdd4XXXXXXX\",\"client_secret\": \"HS5ZeIVsKW0/qqiO9/XcdeWqnF8vtzQrpY8gcdrxg0BXNZXXXXXXX\",\"code\": \"['code']\",\"redirect_uri\": \"http://website.com/foursquare2.php"}",
CURLOPT_HTTPHEADER => array(
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
【问题讨论】:
-
是那些 CURLOPT_URL 等常量值吗?如果不尝试将它们中的每一个都包含在 " 或 ' 中,例如:'CURLOPT_URL',这很可能是由语法错误引起的。
-
尝试将 CURLOPT_POST => 1 添加到选项数组而不是 CURLOPT_CUSTOMREQUEST => "POST",
标签: php oauth-2.0 oauth2client