繁体   English   中英

BigCommerce API PHP - 授权?

[英]BigCommerce API PHP - Authorizing?

我正在使用BigCommerce API的PHP库。 我似乎遇到麻烦并不断​​收到错误消息。 我不确定这是授权问题还是我错过了什么。

我正在使用XAMPP并安装composer以及我需要的BigCommerce PHP包。 我遵循了这个指南: https//github.com/bigcommerce/bigcommerce-api-php

所以这就是我的代码看起来像(凭证X出来):

<?php

require "vendor/autoload.php";

use Bigcommerce\Api\Client as Bigcommerce;


    Bigcommerce::configure(array(

        'store_url' => 'http://store-XXXXXXXX.mybigcommerce.com',
        'username' => 'admin',
        'api_key' => 'xxxxxxxxxxxxxxxxxxxxxxxxx'
    ));


$ping = Bigcommerce::getTime();


if (!$ping ) {
$error = Bigcommerce::getLastError();
print_r($error);
}   


?>

返回: Array ( [0] => stdClass Object ( [status] => 400 [message] => The connection is not secure. API requests must be made via HTTPS. ) )

我想知道它是否与我在配置中使用的“store_url”有关。 所以我将其更改为前端URL(我的商店的真实姓名),这样我收到此消息:

Fatal error: Uncaught exception 'Bigcommerce\Api\NetworkError' with message 'SSL certificate problem: self signed certificate in certificate chain' in C:\xampp\htdocs\test\PSC_BigC\bigcommerce-api-php-master\src\vendor\bigcommerce\api\src\Bigcommerce\Api\Connection.php:274 Stack trace: #0 C:\xampp\htdocs\test\PSC_BigC\bigcommerce-api-php-master\src\vendor\bigcommerce\api\src\Bigcommerce\Api\Connection.php(368): Bigcommerce\Api\Connection->handleResponse() #1 C:\xampp\htdocs\test\PSC_BigC\bigcommerce-api-php-master\src\vendor\bigcommerce\api\src\Bigcommerce\Api\Client.php(423): Bigcommerce\Api\Connection->get('https://psc-dev...') #2 C:\xampp\htdocs\test\PSC_BigC\bigcommerce-api-php-master\src\test.php(19): Bigcommerce\Api\Client::getTime() #3 {main} thrown in C:\xampp\htdocs\test\PSC_BigC\bigcommerce-api-php-master\src\vendor\bigcommerce\api\src\Bigcommerce\Api\Connection.php on line 274

这是因为您使用的是自签名证书。

您需要配置Bigcommerce以忽略该警告。

Bigcommerce::verifyPeer(false);

这有效地打开了它似乎正在使用的cURL客户端的检查。

该错误指出:“API请求必须通过HTTPS进行。”

将您的商店网址更改为“http s ://store-XXXXXXXX.mybigcommerce.com”,因为它是安全的。

来自docs的示例(商店URL需要是HTTPS)。

https://github.com/bigcommerce/bigcommerce-api-php

Bigcommerce::configure(array(
    'store_url' => 'https://store.mybigcommerce.com',
    'username'  => 'admin',
    'api_key'   => 'd81aada4xc34xx3e18f0xxxx7f36ca'
));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM