首页 > 解决方案 > 如何使用 GMB API 制作带有媒体的 localPost?

问题描述

我可以使用GMBapi 制作 localPost。

但是,当我添加媒体时,它给了我一个错误。

错误如下。

{
  "error": {
    "code": 400,
    "message": "Request contains an invalid argument.",
    "errors": [
      {
        "message": "Request contains an invalid argument.",
        "domain": "global",
        "reason": "badRequest"
      }
    ],
    "status": "INVALID_ARGUMENT"
  }
}

我的源代码如下。另外,我从 github 和 GMB 库从这里安装了 google/apiclient

$mediaItem = new \Google_Service_MyBusiness_MediaItem();                                                                                                                                           
$mediaItem->setSourceUrl("https://example.com/test");                                                                                                                                     
$mediaItem->setMediaFormat('PHOTO');                                                                                                                                                               
$media[] = $mediaItem; 
$post = new \Google_Service_MyBusiness_LocalPost(); 
$post->setSummary($summary);
$post->setCallToAction($callToAction);
$post->setMedia($media);
$obj = new \Google_Service_MyBusiness($client); 
$obj->accounts_locations_localPosts->create($accountLocation,$post); 

如果我注释掉

"$post->setMedia($media);", I can make localPost.

你对此有什么建议吗?

此致,

标签: google-my-business-api

解决方案


我自己解决了。

Before:
$mediaItem->setSourceUrl("https://example.com/test");                                                                                                                                     

After:
$mediaItem->setSourceUrl("https://example.com/test.jpg");   

                                                                                                                              

我无法制作 localPost 的原因是图像扩展名应该是图像扩展名。Google API 不允许我们发布没有扩展名的图片。

干杯。


推荐阅读