【发布时间】:2017-07-21 19:13:45
【问题描述】:
我的代码如下所示。我正在尝试使用 eBay 对用户进行身份验证,以便能够获取访问令牌。在将用户重定向回我的重定向 URL 以使用访问令牌交换代码时,我收到错误:
HTTP/1.1 100 继续 HTTP/1.1 400 错误请求内容长度:109 Cneonction:关闭日期:2017 年 3 月 2 日星期四 06:47:51 GMT RlogId: t6ldssk%28ciudbq%60anng%7Fu2h%3F%3Cwk%7Difvqn*2%3D%3F%3E505-15a8dc659e6-0xf3 设置 Cookie:ebay=%5Esbf%3D%23%5E;Domain=.ebay.com;Path=/ X-EBAY-C-REQUEST-ID:ri=v22kQg9yaBLq,rci=2FDiyansIYnkONQC X-EBAY-C-版本:1.0.0 X-EBAY-REQUEST-ID: 15a8dc658f8.a0968eb.5f6ef.fff87b7e![] 内容类型:应用程序/json 连接:保持活动 {"error":"invalid_request","error_description":"'Authorization' 是 缺少标题:","error_uri":null}
我的 POST 请求有什么问题?
$auth_code = $_GET['code'];
$client_id = "Client ID";
$client_secret = "Client Secret";
$redirect_uri = "RuName";
$headers = array (
'Content-Type' => 'application/x-www-form-urlencoded',
'Authorization' => sprintf('Basic %s',base64_encode(sprintf('%s:%s', $client_id, $client_secret)))
);
$apiURL = "https://api.sandbox.ebay.com/identity/v1/oauth2/token";
$urlParams = array (
"grant_type" => "authorization_code",
"code" => urlencode($auth_code),
"redirect_uri" => $redirect_uri
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Should be removed on production
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_HEADER, true );
curl_setopt($ch, CURLOPT_URL, $apiURL);
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers = array ('Authorization' => sprintf('Basic %s',base64_encode(sprintf('%s:%s', $client_id, $client_secret))),'Content-Type' => 'application/x-www-form-urlencoded') );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $urlParams );
$resp = curl_exec ( $ch );
curl_close ( $ch );
print_r ( $resp );
【问题讨论】:
-
能否请您提供完整的 oauth 连接部分到 ebay。我尽我所能,但不能再进一步了。我真的希望我可以使用你的帮助。我真的很感激。谢谢。