1

我无法从ohShopify.php PHP JSON 客户端获得所需的结果。

请原谅我,因为我对 php 等人还很陌生,但会尽可能清楚地解释我的问题。

我不确定是否有这些相关信息,但我在 Windows 7 Pro 64bit 上使用 WAMP 和 PHP 5.3.13。

这是我的 index.php

require 'shopify.php';
$api_key    = '---';
$secret = '---';
$scope      = read_products;

if (isset($_GET['code'])) { 

    $shopifyClient = new ShopifyClient($_GET['shop'], "", $api_key, $secret);
    session_unset();


    $_SESSION['token'] = $shopifyClient->getAccessToken($_GET['code']);
    if ($_SESSION['token'] != '')
        $_SESSION['shop'] = $_GET['shop'];

    header("Location: store.php");
    exit;   

} else {    

    $shop = '---.shopify.com';
    $shopifyClient = new ShopifyClient($shop, "", $api_key, $secret);

    $pageURL = 'http';
    if ($_SERVER["HTTPS"] == "on") { $pageURL .= "s"; }
    $pageURL .= "://";
    if ($_SERVER["SERVER_PORT"] != "80") {
        $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    } else {
        $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    }

    header("Location: " . $shopifyClient->getAuthorizeUrl($scope, $pageURL));
    exit;
}

成功时将位置设置为我的 store.php:

require 'shopify.php';

$sc = new ShopifyClient($_SESSION['shop'], $_SESSION['token'], $api_key, $secret);

try
{
    // Get all products
    $products = $sc->call('GET', '/admin/products.json', array('published_status'=>'published'));




}
catch (ShopifyApiException $e)
{
    /* 
     $e->getMethod() -> http method (GET, POST, PUT, DELETE)
     $e->getPath() -> path of failing request
     $e->getResponseHeaders() -> actually response headers from failing request
     $e->getResponse() -> curl response object
     $e->getParams() -> optional data that may have been passed that caused the failure

    */
}
catch (ShopifyCurlException $e)
{
    // $e->getMessage() returns value of curl_errno() and $e->getCode() returns value of curl_ error()
}

这是我遇到错误的地方。没有设置任何变量。$_SESSION、$api_key 和 $secret 都返回“未定义”。

截屏

我猜我错过了一些东西,但一直在寻找几个小时但无法弄清楚。$_SESSION 怎么可能是未定义的,因为它是一个“超全局”变量。

如果我可以提供更多信息,请告诉我。提前致谢。

4

0 回答 0