可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Sorry for the noobie question but I just wanted to know the process by which I could at least connect to my bigcommerce store and query it via a PHP or curl script.
If someone could help me with simple instructions. i.e download bigcommerce php script, install , generate API on user, install wamp or some other php mac app paste into here blah blah blah I would be eternally grateful.
I have been reading and reading and just obvioulsy missing something as I cant gereneate anything out of the playground section of developer big commerce functionality and dont know where to go from here.
Nearly forgot to mention I am on a mac if that makes a difference
Thanks
Andrew
回答1:
1) Requirements
PHP 5.3 or greater
cUrl extension enabled
2) Create Folder wamp/www/bigcommerceDemo and Download https://github.com/bigcommerce/bigcommerce-api-php/archive/master.zip in it.
3) Install composer with composer install command
4) Create index.php file in bigcommerceDemo folder means your project folder
index.php File :-
<?php
require 'vendor/autoload.php';
use Bigcommerce\Api\Client as Bigcommerce;
Bigcommerce::configure(array(
'store_url' => 'https://xyz-com.mybigcommerce.com/',
'username' => 'admin',
'api_key' => 'dummy92f6fd3df7f140719c1889e78d9c026999p'
));
Bigcommerce::verifyPeer(false);
$ping = Bigcommerce::getTime();
if ($ping) {
//echo $ping->format('H:i:s');
}
Bigcommerce::failOnError();
try {
$orders = Bigcommerce::getOrders();
} catch(Bigcommerce\Api\Error $error) {
echo $error->getCode();
echo $error->getMessage();
}
$products = Bigcommerce::getProducts();
//echo '<pre>'; print_r($products); exit;
echo '<pre>';
foreach($products as $product) {
//print_r($product);
echo $product->name . '---------';
//echo $product->price . '<br>';
}
5) Run localhost/bigcommerceDemo : This file display all products.
回答2:
Simple cURL snippet to get orders
$api_url = 'https://YOUR-API-PATH.mybigcommerce.com/api/v2/orders.json';
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $api_url );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array ('Accept: application/json', 'Content-Length: 0') );
curl_setopt( $ch, CURLOPT_VERBOSE, 0 );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $ch, CURLOPT_USERPWD, "YOUR-USERNAME:YOUR-API-TOKEN" );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
$response = curl_exec( $ch );
$result = json_decode($response);
print_r($result);
Hope this helps
回答3:
The API documentation is pretty good. The key (which I originally struggled to figure out) is that as a starting place it needs to run on a server.
Install xampp or similar that is running PHP. From there make sure to reference the API file, authenticate, code away. I have found that this was the gap in the documentation.
回答4:
you can install MAMP on your mac,
then proceed to http://developer.bigcommerce.com/ to get your api keys.
then just download the Bigcommerce PHP API, see the API Doc to learn to use it.
回答5:
I wouldn't advise using CURL option...
I began this way but highly recommended the PHP API that Bigcommerce have created.
You can find the quickstart documentation @ http://developer.bigcommerce.com/quickstarts/php
If you wanted to do that using PHP API you would only have to write the following...
1.) Install WAMP
2.) Download the PHP API from Github here : https://github.com/bigcommerce/bigcommerce-api-php
3.) Following the instruction on the github page here https://github.com/bigcommerce/bigcommerce-api-php
Ensure that you can 'connect to store' etc and get the correct responses.
If you can't get past this point copy us your code and some errors and will see what we can do!