2

我在尝试通过 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::configure(array('store_url' => 'storeurl', 'username' => 'admin', 'api_key' => '4581223546f2bf73840d84b4802cab039f249404' ));

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

    Bigcommerce::verifyPeer(false);

    $products = Bigcommerce::getProducts();

    foreach($products as $product) { echo $product->name; 回声$产品->价格;}

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

警告:第 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帮助......非常需要......

4

2 回答 2

4

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

Bigcommerce::configure(array(

'store_url' => 'https://store-atka90u.mybigcommerce.com/',
'username' => 'admin',
'api_key' => '4581223546f2bf73840d84b4802cab039f249404'
));
于 2013-07-02T01:15:23.167 回答
0

尝试这个

<?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 和 username ...

于 2013-09-11T20:53:40.803 回答