google-my-business-api - 如何使用 GMB API 制作带有媒体的 localPost?
问题描述
我可以使用GMB
api 制作 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.
你对此有什么建议吗?
此致,
解决方案
我自己解决了。
Before:
$mediaItem->setSourceUrl("https://example.com/test");
After:
$mediaItem->setSourceUrl("https://example.com/test.jpg");
我无法制作 localPost 的原因是图像扩展名应该是图像扩展名。Google API 不允许我们发布没有扩展名的图片。
干杯。
推荐阅读
- hashicorp-vault - 保险柜包装令牌 - 使用次数
- statistics - 有没有办法将 Stata 中的数据从单个观察(例如经历事件的患者数量)转换为多个观察?
- javascript - 使用 JavaScript 中的自定义键将数组转换为对象
- javascript - Javascript Self-Defending是如何工作的,它是如何在美化时进入无限循环的?
- json - 将 Json 响应中的对象列表映射到颤动中的列表
- electron - 为什么 nyc 只从我的 Electron 进程的主进程中捕获文件?
- python - 将两个连续的词视为词频中的一个
- sql - Postgresql“+”符号用于回车/zsh脚本的新行
- javascript - 为什么我不能在 jasmine 的 expectAsync 中使用匿名函数?
- mips - 我如何将 1 添加到内存中的第一个值并将该值存储在相邻的单词中,并将该值的副本放入寄存器 $v0