【问题标题】:not able to connect to bigcommerce api无法连接到 bigcommerce api
【发布时间】:2013-07-01 12:23:12
【问题描述】:

我在尝试通过 bigcommerce api 连接到我的 bigcommerce 帐户时遇到问题.... 我根据这个 url 遵循了以下准则:

  1. 我从这里下载了 bigcommerce.php 文件 https://raw.github.com/bigcommerce/bigcommerce-api-php/master/bigcommerce.php

  2. 然后将此文件包含到我的 index.php 文件中

  3. 然后我尝试在我的 index.php 文件中执行以下代码

     require 'bigcommerce.php';
        use Bigcommerce\Api\Client as Bigcommerce;
    

    Bigcommerce::配置(数组( 'store_url' => 'storeurl', '用户名' => '管理员', 'api_key' => '4581223546f2bf73840d84b4802cab039f249404' ));

    Bigcommerce::setCipher('RC4-SHA');
    

    Bigcommerce::verifyPeer(false);

    $products = Bigcommerce::getProducts();

    foreach($products 作为 $product) { 回声$产品->名称; 回声$产品->价格; }

但这对我不起作用。它显示以下警告

警告:在第 16 行的 C:\wamp\www\bigcommerce\index.php 中为 foreach() 提供的参数无效

然后我按照以下步骤操作:

  1. 我从这里下载了 api 的 ZIP 文件 https://github.com/bigcommerce/bigcommerce-api-php/archive/master.zip

  2. 将该文件提取到我的项目文件夹中,例如 myfolder,即提取文件的目录是 myfolder/bigcommerce-api-php-master/

  3. 然后我包含了 myfolder/bigcommerce-api-php-master/bigcommerce.php

并尝试执行以下代码....

<?php
 require 'bigcommerce-api-php-master/bigcommerce.php';
    use Bigcommerce\Api\Client as Bigcommerce;

    Bigcommerce::configure(array(
    'store_url' => 'https://store-atka90u.mybigcommerce.com/api/v2/',
    'username' => 'admin',
    'api_key' => '4581223546f2bf73840d84b4802cab039f249404'
    ));

    Bigcommerce::setCipher('RC4-SHA');
Bigcommerce::verifyPeer(false);

$products = Bigcommerce::getProducts();

foreach($products as $product) {
    echo $product->name;
    echo $product->price;
}
?>

但即使在我已经在我的帐户中添加了 2 种产品后,它也会再次显示相同的警告。

警告:在第 16 行的 C:\wamp\www\bigcommerce\index.php 中为 foreach() 提供的参数无效

任何形式的帮助都会得到满足..... plzzzz 帮助.... 急需....

【问题讨论】:

    标签: php bigcommerce


    【解决方案1】:

    所以,那是因为路径中有完整的 URL。 将其更改为以下内容 -

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

    【讨论】:

    • 非常感谢兄弟.....!!!!!!你把我从一个大问题中解救了出来……你能告诉我是否有办法检查这些凭据(即 store_url、用户名、api_key)是否有效……我的意思是说我们如何检查是否此信息是否正确.. 还有一个问题是 bigcommerce 中的 store_url 是否唯一.. 如果您对此有任何解决方案,请回复.. 等待您的回复.. ...
    • @saran 您可以像Store 一样进行轻量级 API 调用,如果您得到正确的回复,则此凭据有效,否则 BigCommerce 将抛出无效凭据错误。
    【解决方案2】:

    试试这个

    <?php
    // provision for laziness
    if( 
        (array_key_exists('store_url', (array)$settings)) &&
        (array_key_exists('username', $settings)) && 
        (array_key_exists('api_key', $settings)) 
    ) {
        // Config Basic
        BC::configure(
            array(
                'store_url' => $settings['store_url'],
                'username'  => $settings['username'],
                'api_key'   => $settings['api_key']
            )
        );
    
        // Set Cipher if needed
        if(array_key_exists('cipher',$settings)) {
            BC::setCipher('RC4-SHA');
        } else {
            BC::verifyPeer(false);
        }
    
        // Set Proxy if needed
        if(array_key_exists('proxy',$settings)) {
            BC::useProxy($settings['proxy']['url'], $settings['proxy']['port']);
        }
    }
    // Run your code here...
    

    显然您需要配置 $settings 数组以至少包含 store_url、api_key 和用户名...

    【讨论】:

      猜你喜欢
      • 2018-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-12
      • 2022-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多