簡體   English   中英

在 PHP 中使用 CURL 在 Shopify 中添加產品圖像 - Cloudflare 錯誤

[英]Adding Product Images in Shopify using CURL In PHP - Cloudflare Errors

我正在嘗試使用 PHP 中的CURL將圖像添加到我的產品中圖片

這是使用 CURL CLI 的樣子,但我正在嘗試通過 PHP 使用它:

curl -d '{"image":{"src":"http://example.com/rails_logo.gif"}}' \
-X POST "https://your-development-store.myshopify.com/admin/api/2022-07/products/632910392/images.json" \
-H "X-Shopify-Access-Token: {access_token}" \
-H "Content-Type: application/json"

我嘗試了多種不同的格式,但不斷收到以下格式的 Cloudflare 錯誤:

$ch = curl_init("https://STORENAME.myshopify.com/admin/api/2022-07/products/632910392/images.json");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Shopify-Access-Token: SECRETTOKEN"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_URL, "http://example.com/rails_logo.gif");
curl_setopt($ch, CURLOPT_INFILE, "http://example.com/rails_logo.gif");
curl_setopt($ch, CURLOPT_POSTFIELDS,'{"image":{"position":'1',"src":"http://example.com/rails_logo.gif"}}');
$responseTmp = curl_exec($ch);

我從 Cloudflare 收到“BAD REQUEST”和“1020”錯誤,我認為是因為我的請求中的某些內容格式不正確。

將不勝感激任何建議。

如果它可以幫助其他人進一步走下去 - 這就是 Shopify 期望通過 php curl 上傳圖像的方式:

$image = json_encode(array('image'=> array('src' => $imageUrl)));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $image);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM