php - 无法从 Bigcommerce API 获取访问 token ,客户端 ID 无效

标签 php oauth oauth-2.0 bigcommerce

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

响应是 HTTP/1.1 400 错误请求 {"error":"无效的客户端 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());

最佳答案

我明白了!

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

关于php - 无法从 Bigcommerce API 获取访问 token ,客户端 ID 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33865181/

相关文章:

php - 如何将多个查询结果传递给新查询

php - 连接 postgres 和 laravel

oauth - Laravel 单点登录

node.js - Node js请求的授权问题

oauth-2.0 - 错误 400 : invalid_scope "https://www.googleapis.com/auth/chat.bot"

node.js - 验证错误: Validation failed mongoose

oauth-2.0 - 对于 Google+ API 和 OAuth 关闭,我需要更改哪些内容?

php - 编辑时如何设置单选按钮的值?

javascript - 我想在 php 中每 3 秒刷新一次谷歌地图而不是整个页面

php - 使用 Laravel API 实现 OAuth 2.0 身份验证