我正在尝试获取访问令牌,以便我可以开始构建适用于BigCommerce的应用程序。我一直在关注这里的文档:https://developer.bigcommerce.com/api/callback。我正在使用PHP客户端进行Bigcommerce。
响应是HTTP / 1.1 400错误请求{"错误":"无效的客户端ID。"}。 我发誓我正在使用正确的客户端ID和客户端密码!或者至少它们是我点击" View Client 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());
答案 0 :(得分:2)
我明白了!
我刚刚删除了行$connection->useUrlencoded();
,因为它需要以“Content-Type:application / json”的形式发送,我将其发送为“Content-Type:application / x-www-form-urlencoded”