我想从我的shopify商店退回产品并将预期返回的json转储到页面上。没有产品通过代码返回,但如果我直接转到下面表格中的网址,我会在页面上显示预期的json:
https://API_KEY:PASSWORD@your-store.myshopify.com/admin/products.json
任何人都可以帮助我使用我用来连接shopify的this package来返回json吗?我也在使用Laravel 5.
我注意到Input调用没有返回任何内容:
Input::get('code');
Input::all();
我将此添加到app.php:
'Input' => Illuminate\Support\Facades\Input::class,
我收到了这个错误:
ERROR #22: The requested URL returned error: 401
in api.php line 309 at API->call(array('METHOD' => 'GET', 'URL' => '/admin/products.json?page=1')) in routes.php line 87
这是我的路线:
Route::get('/show_products', function() {
$shopify = App::make('ShopifyAPI');
// This creates an instance of the Shopify API wrapper and
// authenticates our app.
$shopify = App::make('ShopifyAPI', [
'API_KEY' => 'api_key',
'API_SECRET' => 'api_secret',
'SHOP_DOMAIN' => 'shop_domain.myshopify.com',
'ACCESS_TOKEN' => 'access_token'
]);
$shopify->installURL(['permissions' => array('read_products', 'write_products'), 'redirect' => 'https://dev.shopify.com/public/']);
try {
$verify = $shopify->verifyRequest(Input::all(), true);
if ($verify)
{
$code = Input::get('code');
echo "code: ".$code; // no code returned
$accessToken = $shopify->getAccessToken($code);
echo "accessToken: ".$accessToken; // no access token
}
else
{
echo "issue with data";
// Issue with data
}
}
catch (Exception $e)
{
echo '<pre> Error: ' . $e->getMessage() . '</pre>';
}
// Gets a list of products
$result = $shopify->call([
'METHOD' => 'GET',
'URL' => '/admin/products.json?page=1'
]);
$products = $result->products;
print_r($products);
exit;
});
答案 0 :(得分:0)
我在Android上遇到过这个问题。如果我在浏览器中,使用密钥/秘密访问URL的产品工作正常,但尝试从设备对该URL进行基本GET尝试失败。 我无法弄清楚原因,但我最终在请求中设置了标题,并且效果很好。
你在哪里
https://API_KEY:PASSWORD@your-store.myshopify.com/admin/products.json
相反,请求
https://your-store.myshopify.com/admin/products.json
但是将标题x-shopify-access-token
设置为PASSWORD