我正在尝试获取访问令牌,以便开始构建一个可与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:application/x-www-form-urlencoded"