文档中列出的所有现有端点真的仍然适用于v4.9吗?(即迄今为止未被v1取代的那些)



我尝试过使用旧的v4.9端点,这些端点到目前为止还没有被v1取代,例如:

https://developers.google.com/my-business/reference/rest/v4/accounts.locations/reportInsights
https://developers.google.com/my-business/reference/rest/v4/accounts.locations.reviews

但是,这些端点都不再工作。

我使用的PHP客户端缺少这些端点,但使用这里列出的官方v4.9库:https://developers.google.com/my-business/samples/previousVersions,我已经能够访问一些旧的端点,如评论。

但是,它们不再返回任何数据,或者数据对象为空。

有人经历过类似的问题吗?

v4.9(尚未弃用(端点(如评论、见解等(正在运行,但官方库已损坏并搞砸

我不得不使用Guzzle客户端直接到达端点来编写替换代码。因此,您需要自己为这些v4.9端点从头开始编写API库,因为官方库不起作用。

如何获取评论:

public static function listReviews($client, $params, $account, $location)
{
$response = $client->authorize()->get('https://mybusiness.googleapis.com/v4/' . $account . '/' . $location . '/reviews', ['query' => $params]);
return json_decode((string) $response->getBody(), false);
}

如何获取见解:

/** v4.9 working 02/2022 **/
public static function reportInsights($client, $params, $account)
{
try {
$response = $client->authorize()->post('https://mybusiness.googleapis.com/v4/' . $account . '/locations:reportInsights', [
GuzzleHttpRequestOptions::JSON => $params,
]);
} catch (GuzzleHttpExceptionRequestException $ex) {
return $ex->getResponse()->getBody()->getContents();
}
return json_decode((string) $response->getBody(), false);
}

如何为见解准备有效载荷:

$params = new stdClass();
$params->locationNames = $account->name . '/' . $location->name;
$time_range = new stdClass();
$time_range->startTime = Carbon::parse('3 days ago 00:00:00')->toISOString();
$time_range->endTime = Carbon::parse('2 days ago 00:00:00')->toISOString();
if ($force == 'complete') {
$time_range->startTime = Carbon::parse('17 months ago 00:00:00')->toIso8601ZuluString();
$time_range->endTime = Carbon::parse('3 days ago 00:00:00')->toIso8601ZuluString();
}
$params->basicRequest = new stdClass();
$params->basicRequest->timeRange = $time_range;
$params->basicRequest->metricRequests = new stdClass();
$metric_request = new stdClass();
$metric_request->metric = 'ALL';
$metric_request->options = ['AGGREGATED_DAILY'];
$params->basicRequest->metricRequests = [
$metric_request,
];

注意:如果您得到的是空的洞察响应,您必须使用新的v1 API调用检查验证,例如:

$verifications = Google_Service_MyBusinessVerifications($client)->locations_verifications->listLocationsVerifications($location->getName());
$verification = '0';
if ($verifications->getVerifications()) {
$verification = $verifications->getVerifications()[0]->getState();
}

使用具有现有令牌的官方API客户端(需要通过OAuth2获取(:

$provider = new GoogleClientServiceProvider(true);
$client = $provider->initializeClient($known_token, ['https://www.googleapis.com/auth/plus.business.manage', 'https://www.googleapis.com/auth/drive']);

最新更新