PHP code example of vincenth520 / shopify

1. Go to this page and download the library: Download vincenth520/shopify library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vincenth520 / shopify example snippets



session_start();
$APP_API_KEY = ''; //api key
$APP_SECRET = ''; //app secret

$client = new Shopify\Shopify($_GET['shop'], $APP_API_KEY, $APP_SECRET);
$_SESSION['client_id'] = time();
$random_state = $_SESSION['client_id'];

$rediect_url = 'http://localhost/shopify/shopify/redirect.php';  //this is your redirect url

$client->authorizeUser($rediect_url, [
  'read_products',
  'write_products',
], $random_state);


session_start();
'; //api key
$APP_SECRET = ''; //app secret


$client = new Shopify\Shopify($_GET['shop'], $APP_API_KEY, $APP_SECRET);
$client->setState($_SESSION['client_id']);
if ($token = $client->getAccessToken()) {
  $_SESSION['shopify_access_token'] = $token;
  $_SESSION['shopify_shop_domain'] = $_GET['shop'];
}
else {
  die('invalid token');
}

$client = new Shopify\Shopify($_SESSION['shopify_shop_domain'], $APP_API_KEY, $APP_SECRET);
$client->getShopInfo();

$client = new Shopify\Shopify($_SESSION['shopify_shop_domain'], $APP_API_KEY, $APP_SECRET);
$client->getWebhooks();

$client = new Shopify\Shopify($_SESSION['shopify_shop_domain'], $APP_API_KEY, $APP_SECRET);
$type = 'collections/create'; //topics  [see:https://help.shopify.com/api/reference/webhook]
$address = 'https://baidu.com'; //address URIs
$format = 'json'; //json or xml
$client->addWebhook($type,$address,$format);