dream3323 2014-12-19 18:36
浏览 48

如何使用PHP连接bigCommerce API?

I'm trying to connect to an API, I'm a front end dev, not too familiar with server side & php. Would love your help.

This is the repository - https://github.com/bigcommerce/bigcommerce-api-php I'm not using composer.

They say there -

To use the API client in your PHP code, ensure that you can access Bigcommerce\Api in your autoload path

I've been trying to figure out how to do that, but I just can't figure it out.

This is the code that i wrote -

 <?php
/**
 * Created by PhpStorm.
 * User: Alex
 * Date: 12/15/14
 * Time: 9:29 PM
 */
require '../bigcommerce.php';

//echo realpath('../bigcommerce/api/client');
use ֿֿBigcommerce\Api\Client as Bigcommerce;

Bigcommerce::configure(array(
    'store_url' => '', //my store url
    'username'  => 'admin',
    'api_key'   => '' //my api key
));
$ping = Bigcommerce::getTime();

if ($ping) echo $ping->format('H:i:s');

$products = Bigcommerce::getProducts();

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

I use:

spl_autoload_register(function ($class) {
    include  $class . '.php';
});

I'm sorry, but i'm finding it quite hard to explain the question. I need to include classes with autoload but it doesn't work, i have no idea why. It keeps telling me that failed to open stream.

  • 写回答

1条回答 默认 最新

  • doujiu8918 2014-12-23 04:57
    关注

    If you are not using the composer method, you need to make sure you have a copy of bigcommerce.php on your server. That's the only file you need, you don't need to use autoload. Bigcommerce.php has all the classes in it already. You can simply copy and paste it from here: https://github.com/bigcommerce/bigcommerce-api-php/blob/master/bigcommerce.php

    require '../bigcommerce.php'; says that the bigcommerce file is stored one directory higher than your working directory. Is this so? If you are using it in your current directory, then it should be require('./bigcommerce.php');

    Other than that, your code appears correct.

    If that doesn't work, run command: chmod 0644 ./bigcommerce.php on that file, to ensure correct permissions.

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么