使用 REST 将视频添加到 Magento 2 产品

问题描述 投票:0回答:2

Magento 版本 2.2.5 有问题的端点 /V1/products/{sku}/media 方法:POST

我正在尝试使用 Magento 提供的 API 端点在产品 sku 下添加视频。

{
 "entry": {
     "media_type": "external-video",
     "label": "Video 2",
     "position": 2,
     "disabled": false,
     "types": ["thumbnail"],
     "content" : {
         "base64_encoded_data": "encoded image data ",
         "type": "image/jpeg",
         "name": "0.jpg"
     },
     "extension_attributes": {
         "video_content": {
             "media_type": "external-video",
             "video_provider": "youtube",
             "video_url": "some youtube video url",
             "video_title": "some title",
             "video_description": "",
             "video_metadata": ""
         }
     }
}

我从这个调用中得到的响应是“无效的选项值”,我在本地环境中对此进行了调试,这导致我在 Magento\Catalog\Model\Product\GalleryGalleryManagement.php 中第 70 行的 ProductRepository->save() 期间失败

这是我的负载问题还是实际的 magento 错误?

magento2.2 magento-rest-api
2个回答
0
投票

通过使用 POST /V1/products 或 PUT /V1/products/{sku} 端点直接添加视频解决了此问题。

post方法示例:

{ 
  "product": {
     "sku": "some-sku",
     ..... other product data,
     "media_gallery_entries": {
         "media_type": "external-video",
         "label": "Video 2",
         "position": 2,
         "disabled": false,
         "types": [],
         "content" : {
             "base64_encoded_data": "encoded image data ",
             "type": "image/jpeg",
             "name": "0.jpg"
          },
          "extension_attributes": {
              "video_content": {
                  "media_type": "external-video",
                  "video_provider": "youtube",
                  "video_url": "some youtube video url",
                  "video_title": "some title",
                  "video_description": "",
                  "video_metadata": ""
          }
     }
   }
}

我对 Magento 的 MediaGallery POST 端点(/V1/products/{sku}/media)没有运气。


0
投票

如果您想将视频添加到产品页面,那么为什么您不尝试使用 YouTube API?

您只需按照以下步骤操作:

  • 通过 godle 开发者控制台生成 YouTube API 密钥
  • 然后通过转到 STORES --> Configuration
  • 将 Youtube API 密钥添加到您的 Magento 2
  • 然后添加视频网址
© www.soinside.com 2019 - 2024. All rights reserved.