【发布时间】:2018-10-31 19:07:38
【问题描述】:
我正在尝试从 BigCommerce 检索访问令牌。我正在按照此页面上的说明进行操作:https://developer.bigcommerce.com/apps/callback
当我尝试检索访问令牌时,我收到了无效范围错误。代码如下:
public function access_token_get(){
print_r($_GET);
$tokenUrl = "https://login.bigcommerce.com/oauth2/token";
$connection = new Connection();
$connection->setCipher('RC4-SHA');
$connection->verifyPeer(false);
$response = $connection->post($tokenUrl, array(
"client_id" => "123456",
"client_secret" => "123456",
"redirect_uri" => "https://my-registered-auth-callback.com/",
"grant_type" => "authorization_code",
"code" => urlencode($_GET['code']),
"scope" => urlencode($_GET['scope']),
"context" => urlencode($_GET['context'])
));
print_r($response);
print_r($connection->getLastError());
$token = $response->access_token;
print_r($token);
}
当这段代码运行时,我得到一个空的$response。我添加了getLastError() 行以查看发生了什么,它正在输出:
stdClass Object ( [error] => Invalid scope(s). )
这些是 GET 请求输出的参数:
Array ( [code] => 2idy1ozvee8s0ddlbg3jgquzgtr55gd [context] => stores/xxxxxx [scope] => store_v2_orders store_v2_products store_v2_customers store_v2_content store_v2_marketing store_v2_information_read_only users_basic_information )
为什么我会收到此“无效范围”错误?我还尝试对单个范围进行硬编码以查看是否可行,例如,只执行"scope"=>"store_v2_orders",但是当我这样做时,我收到一条错误消息,提示该范围尚未被用户授予。
【问题讨论】:
标签: php oauth bigcommerce