我正在尝试通过API使用PHP将图像上传到我的shopify商店,但是失败。
$images = array
(
"image"=>array
(
"attachment" => $borderedImage,
"filename" => "rails_logo.jpg"
)
);
# Making an API request can throw an exception
$products = $shopify('POST /admin/products/#1246990273/images.json', $images);
但是,我没有在错误日志中显示以下消息,而不是获取NULL
[2015-07-17 23:14:57] local.INFO: <html><body>You are being <a href="https://SHOPNAME.myshopify.com/admin/auth/login">redirected</a>.</body></html>
我以为这是我的访问令牌或api密钥的问题,但是我可以进行其他API调用来获取诸如产品列表和创建新产品之类的信息。它只是在创建一个新图像而出现问题。
很难获得任何信息,因为似乎没有多少人正在为shopify构建PHP应用程序。
是否有其他人使用PHP应用程序成功将图像上传到api?
这是一个例子。假设您使用的是通过OAuth(而不是从私有应用程序)获得的访问令牌,并且您要从URL上传图像。访问令牌,商店URL和产品ID将需要交换为您自己的。您可以在此处找到Product Image API文档。希望这可以帮助!
<?php
$token = 'youraccesstoken';
$ch = curl_init("https://yourstore.myshopify.com/admin/products/934765124/images.json");
$image = json_encode(array('image'=> array('src' => 'https://cdn.shopify.com/shopify-marketing_assets/static/shopify-default.png')));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $image);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"X-Shopify-Access-Token: $token"
));
$result = curl_exec($ch);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句