Php 如何发布topicType优惠的localPost?
我正试图让谷歌成为我的业务localPost,以PHP提供topicType 我安装了google/apiclient 2.7。 另外,我有来自GMB站点的客户端库,如下所示。 我制作了以下源代码Php 如何发布topicType优惠的localPost?,php,google-my-business-api,Php,Google My Business Api,我正试图让谷歌成为我的业务localPost,以PHP提供topicType 我安装了google/apiclient 2.7。 另外,我有来自GMB站点的客户端库,如下所示。 我制作了以下源代码 $offer = new \Google_Service_MyBusiness_LocalPostOffer(); $offer->setCouponCode($couponCode); $offer->setTermsConditions($termsCondition);
$offer = new \Google_Service_MyBusiness_LocalPostOffer();
$offer->setCouponCode($couponCode);
$offer->setTermsConditions($termsCondition);
$offer->setRedeemOnlineUrl($redeemOnlineUrl);
$schedule = new \Google_Service_MyBusiness_TimeInterval();
$date = new \Google_Service_MyBusiness_Date();
$date->setDay(6);
$date->setMonth(10);
$date->setYear(2020);
$time = new \Google_Service_MyBusiness_TimeOfDay();
$time->setHours(10);
$time->setMinutes(0);
$time->setMinutes(0);
$time->setSeconds(0);
$time->setNanos(0);
$schedule->setStartDate($date);
$schedule->setStartTime($time);
$date->setDay(6);
$date->setMonth(10);
$date->setYear(2020);
$time->setHours(19);
$time->setMinutes(0);
$time->setSeconds(0);
$time->setNanos(0);
$schedule->setEndDate($date);
$schedule->setEndTime($time);
$event = new \Google_Service_MyBusiness_LocalPostEvent();
$event->setTitle($title);
$event->setSchedule($schedule);
$post = new \Google_Service_MyBusiness_LocalPost();
$post->setSummary($summary);
$post->setOffer($offer);
$post->setEvent($event);
$post->setTopicType("OFFER");
$obj = new \Google_Service_MyBusiness($this->getClient('mybusiness'));
$obj->accounts_locations_localPosts->create($accountLocation,$post)
但是,它给我以下错误消息
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"errors": [
{
"message": "Request contains an invalid argument.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}
你对此有什么建议吗
致以最诚挚的问候,我无法发布报价的原因是我在设置endDate和endTime时没有重新初始化以下内容
Google_Service_MyBusiness_Date
Google_Service_MyBusiness_TimeOfDay
因此,我可能会重新初始化如下
$date = new \Google_Service_MyBusiness_Date();
$time = new \Google_Service_MyBusiness_TimeOfDay()
这段代码为我创建了一个offer post
$service=新谷歌服务\我的业务($client);
$post\u body=new\Google\u Service\u MyBusiness\u LocalPost;
$post_body->setLanguageCode('en');
$post_body->setSummary('test offer_1');
$offer=new\Google\u Service\u MyBusiness\u LocalPostOffer;
$offer->setCouponCode('TEST-OFFE-CODE');
$offer->setRecommensionOnlineURL('https://www.example.com');
$offer->setTermsConditions('offer无效,仅测试offer');
$post_body->setOffer($offer);
$event=new\Google\u Service\u MyBusiness\u LocalPostEvent;
$event->setTitle('testoffer post');
$schedule=new\Google\u Service\u MyBusiness\u TimeInterval;
$startdate=new\Google\u Service\u MyBusiness\u时间间隔;
$date=new\Google\u Service\u MyBusiness\u date;
$date->setYear('2021');
$date->setMonth('10');
$date->setDay('02');
$schedule->setStartDate($date);
$starttime=new\Google\u Service\u MyBusiness\u时间范围;
$time=new\Google\u Service\u MyBusiness\u TimeOfDay;
$time->setHours('9');
$time->setMinutes('0');
$time->setSeconds('0');
$time->setNanos('0');
$schedule->setStartTime($time);
$endDate=new\Google\u Service\u MyBusiness\u TimeInterval;
$date=new\Google\u Service\u MyBusiness\u date;
$date->setYear('2021');
$date->setMonth('10');
$date->setDay('03');
$schedule->setEndDate($date);
$endtime=new\Google\u Service\u MyBusiness\u时间范围;
$time=new\Google\u Service\u MyBusiness\u TimeOfDay;
$time->setHours('11');
$time->setMinutes('0');
$time->setSeconds('0');
$time->setNanos('0');
$schedule->setEndTime($time);
$event->setSchedule($schedule);
$post_body->setEvent($event);
$post_body->setTopicType('OFFER');
$media=new\Google\u Service\u MyBusiness\u MediaItem;
$media->setMediaFormat('PHOTO');
$media->setSourceUrl('https://image.shutterstock.com/image-photo/white-transparent-leaf-on-mirror-260nw-1029171697.jpg');
$post_body->setMedia($media);
$accounts=$service->accounts->listAccounts()->getAccounts();
$locations=$service->accounts\u locations->listAccountsLocations($accounts[0]['name']);
$post=$service->accounts\u locations\u localPosts->create($locations[0]['name'],$post\u body);