eBay API总是在生产时返回invalid_client但是沙箱工作正常[关闭]

问题描述 投票:3回答:3

我已经在这几天了,我似乎无法找到解决方案。

我正在尝试通过ebay API授权获取用户令牌以进行进一步操作。

当我使用沙箱环境时,一切都很好,但是一旦我使用生产,我就会收到以下错误:

{"error":"invalid_client","error_description":"client authentication failed"}

我的文件结构如下:

config.php文件:

<?php
    /* SAndbox 
$config = [
    'client_id' => 'xxxxx-xxxxxx-SBX-e55b66fda-63c7e331',
    'client_secret' => 'SBX-xxxxxx-dxxxxxb-47cb-9bee-f33b',
    'ru_name' => 'xxxxxxxxx-oxxxxas-xxxxxxx-tsuggc',
    'login_url' => 'https://auth.sandbox.ebay.com/oauth2/authorize',
    'oauth_url' => 'https://api.sandbox.ebay.com/identity/v1/oauth2/token',
    'api_scopes' => ['https://api.ebay.com/oauth/api_scope/sell.inventory'],
];
*/

$config = [
    'client_id' => 'xxxxxx-CxxxxxxT-PRD-455bfe8ea-7e445131',
    'client_secret' => 'PRD-797xxxx7bf-d5xxxc-4a19-axxade-ab8xx6',
    'ru_name' => 'xxxxxxx-osxxxxxxas-CxxxxS-hjlalp',
    'login_url' => 'https://auth.ebay.com/oauth2/authorize',
    'oauth_url' => 'https://api.ebay.com/identity/v1/oauth2/token',
    'api_scopes' => ['https://api.ebay.com/oauth/api_scope/sell.inventory'],
];

getLogin.php:

<?php
include_once 'config.php';

$url = $config['login_url'];
$url .= '?client_id='.$config['client_id'];
$url .= '&response_type=code';
$url .= '&redirect_uri='.urlencode($config['ru_name']);
$url .= '&scope='.implode(' ', $config['api_scopes']);
echo "<a href='{$url}'>login</a><br/><br/>";


die();

login.php(授权后我被重定向):

<?php
include_once 'config.php';
echo "<pre>";
$code = $_GET['code'];
$authorization = 'Basic '.base64_encode($config['client_id'].':'.$config['client_secret']);
print_r($config);
$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => $config['oauth_url'],
    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=client_credentials&code=".$code."&redirect_uri=".$config['ru_name'],
    CURLOPT_HTTPHEADER => [
        "Authorization: ".$authorization,
        "Content-Type: application/x-www-form-urlencoded",
        "cache-control: no-cache",
    ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);
$info = curl_getinfo($curl);
curl_close($curl);




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

任何和所有的帮助将不胜感激,因为我要把头发拉出来!

php oauth ebay ebay-api
3个回答
2
投票

我不认为它与你的代码有任何关系。它可能与API调用限制有关。您可以使用其他API客户端进行测试,也可以使用第二个链接验证配额。


0
投票

你似乎拥有所需的所有有效信息,唯一看起来很可疑的是:你已经获得了范围

$url .= '&scope='.implode(' ', $config['api_scopes']);

但我认为你没有包括这个范围

  CURLOPT_POSTFIELDS => "grant_type=client_credentials&code=".$code."&redirect_uri=".$config['ru_name'],

0
投票
curl_setopt($curl_handle, CURLOPT_POSTFIELDS,http_build_query($post_data));

请在您的Curl帖子请求中包含http_build_query($ post_data)。

© www.soinside.com 2019 - 2024. All rights reserved.