我正在尝试获取访问 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/