【问题标题】:Can't get access token from Bigcommerce API, invalid client ID无法从 Bigcommerce API 获取访问令牌,客户端 ID 无效
【发布时间】:2018-02-11 03:02:10
【问题描述】:

我正在尝试获取访问令牌,以便开始构建与 BigCommerce 一起使用的应用程序。我一直在关注这里的文档:https://developer.bigcommerce.com/api/callback。我正在为 Bigcommerce 使用 PHP 客户端。

响应是 HTTP/1.1 400 Bad Request {"error":"Invalid client id."}。 我发誓我使用的是正确的客户端 ID 和客户端密码!或者至少当我在开发者门户的草稿应用上单击“查看客户端 ID”时显示的是它们。

我到底做错了什么?

$request = $_REQUEST;

require_once 'vendor/autoload.php';

use Bigcommerce\Api\Connection;
$tokenUrl = "https://login.bigcommerce.com/oauth2/token";
$connection = new Connection();
$connection->verifyPeer();
$connection->useUrlencoded();
$response = $connection->post($tokenUrl, array(
    "client_id" => "", //I won't type it here but it is correct
    "client_secret" => "", //also correct        
    "redirect_uri" => "https://127.0.0.1/project-custom/oauth.php", //this is the Auth Callback URL
    "grant_type" => "authorization_code",
    "code" => $request["code"], //when I echo these variables out they work
    "scope" => $request["scope"],
    "context" => $request["context"],
));  

print_r($connection->getLastError());

【问题讨论】:

  • 我看到你有 id 的引号,也许删除它们
  • 嗯,不,那没用。 :( 从键中删除它们给了我这个通知:“使用未定义的常量 client_id - 假定为'client_id'”并将它们从值中删除只会导致语法错误。

标签: php oauth oauth-2.0 bigcommerce


【解决方案1】:

我想通了!

我刚刚删除了 $connection->useUrlencoded(); 行,因为它需要作为“Content-Type: application/json”发送,而我将它作为“Content-Type: application/x-www-form-urlencoded”发送

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-10
    • 2018-03-25
    • 2018-01-08
    • 1970-01-01
    • 1970-01-01
    • 2015-02-11
    • 2015-06-02
    • 2020-06-12
    相关资源
    最近更新 更多