如何解决如何发布topicType优惠的localPost?
我正在尝试将PHP的topicType提供给Google My Business localPost。
我安装了google / apiclient 2.7。 另外,我有来自GMB网站的客户端库,如下所示。 https://developers.google.com/my-business/samples/google-api-services-mybusiness-v4p7-php-rev-20200824-1.zip
我编写了以下源代码。
$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"
}
}
您对此有何建议?
最诚挚的问候,
解决方法
此代码为我创建优惠帖子。
$service = new Google_Service_Mybusiness($client);
$post_body = new \Google_Service_MyBusiness_LocalPost;
$post_body->setLanguageCode('en');
$post_body->setSummary('test offer_1');
$offer = new \Google_Service_MyBusiness_LocalPostOffer;
$offer->setCouponCode('TEST-OFFE-CODE');
$offer->setRedeemOnlineUrl('https://www.example.com');
$offer->setTermsConditions('Offer not valid,it only test offer');
$post_body->setOffer($offer);
$event = new \Google_Service_MyBusiness_LocalPostEvent;
$event->setTitle('Test Offer post');
$schedule= new \Google_Service_MyBusiness_TimeInterval;
$startdate = new \Google_Service_MyBusiness_TimeInterval;
$date= new \Google_Service_MyBusiness_Date;
$date->setYear('2021');
$date->setMonth('10');
$date->setDay('02');
$schedule->setStartDate($date);
$starttime = new \Google_Service_MyBusiness_TimeRange;
$time = new \Google_Service_MyBusiness_TimeOfDay;
$time->setHours('9');
$time->setMinutes('0');
$time->setSeconds('0');
$time->setNanos('0');
$schedule->setStartTime($time);
$endDate = new \Google_Service_MyBusiness_TimeInterval;
$date= new \Google_Service_MyBusiness_Date;
$date->setYear('2021');
$date->setMonth('10');
$date->setDay('03');
$schedule->setEndDate($date);
$endtime = new \Google_Service_MyBusiness_TimeRange;
$time = new \Google_Service_MyBusiness_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_Service_MyBusiness_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_locations->listAccountsLocations($accounts[0]['name']);
$post = $service->accounts_locations_localPosts->create($locations[0]['name'],$post_body);
,
之所以不能发布报价,是因为在设置endDate和endTime时没有重新初始化以下内容。
Google_Service_MyBusiness_Date
Google_Service_MyBusiness_TimeOfDay
因此,我可能会如下重新初始化。
$date = new \Google_Service_MyBusiness_Date();
$time = new \Google_Service_MyBusiness_TimeOfDay()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。