文档中列出的所有现有端点是否真的仍然适用于 v4.9? (即到目前为止未被 v1 取代的那些)
Are all existing endpoints listed in documentation really still working for v4.9? (i.e. those not replaced by v1 so far)
我尝试使用到目前为止尚未被 v1 取代的旧 v4.9 端点,例如:
https://developers.google.com/my-business/reference/rest/v4/accounts.locations/reportInsights
https://developers.google.com/my-business/reference/rest/v4/accounts.locations.reviews
但是,这些端点中的 none 个可以继续使用。
我正在使用缺少这些端点的 PHP 客户端,但使用此处列出的官方 v4.9 库:https://developers.google.com/my-business/samples/previousVersions
我已经能够访问一些旧的端点,例如评论.
但是它们不再return任何数据或数据对象为空。
有人遇到过类似的问题吗?
评论、见解等 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', [
\GuzzleHttp\RequestOptions::JSON => $params,
]);
} catch (\GuzzleHttp\Exception\RequestException $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']);
我尝试使用到目前为止尚未被 v1 取代的旧 v4.9 端点,例如:
https://developers.google.com/my-business/reference/rest/v4/accounts.locations/reportInsights
https://developers.google.com/my-business/reference/rest/v4/accounts.locations.reviews
但是,这些端点中的 none 个可以继续使用。
我正在使用缺少这些端点的 PHP 客户端,但使用此处列出的官方 v4.9 库:https://developers.google.com/my-business/samples/previousVersions
我已经能够访问一些旧的端点,例如评论.
但是它们不再return任何数据或数据对象为空。
有人遇到过类似的问题吗?
评论、见解等 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', [
\GuzzleHttp\RequestOptions::JSON => $params,
]);
} catch (\GuzzleHttp\Exception\RequestException $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']);