Open3
Google Business Profile APIs

公式サイト
概要
Business Profile自体の概要は以下を参照
Business Profileに関する様々な情報は以下を参照
APIの種類と役割
Account Management API
(1)- Google 上のビジネスへのアクセスを管理するためのインターフェース
- サービスエンドポイント
https://mybusinessaccountmanagement.googleapis.com
Business Calls API
(2)- Google 上のビジネス情報のビジネス電話に関する情報を管理し、ビジネス拠点への不在着信の件数などの分析情報を収集
- サービスエンドポイント
https://mybusinessbusinesscalls.googleapis.com
Lodging API
(3)- Google で宿泊施設のビジネス情報を管理
- サービスエンドポイント
https://mybusinesslodging.googleapis.com
Place Actions API
(4)- Google のビジネス情報の位置情報アクション リンクを管理するためのインターフェース
- サービスエンドポイント
https://mybusinessplaceactions.googleapis.com
Notifications API
(5)- ビジネス アカウントの通知設定を管理
- サービスエンドポイント
https://mybusinessnotifications.googleapis.com
Verifications API
(6)- ビジネス情報のオーナー確認に関する操作を行うためのインターフェース
- サービスエンドポイント
https://mybusinessverifications.googleapis.com
Business Information API
(7)- Google でビジネス情報を管理するためのインターフェース
- サービスエンドポイント
https://mybusinessbusinessinformation.googleapis.com
Q&A API
(8)- 特定のリスティングに関する質問や回答を掲載するためのインターフェース
- サービスエンドポイント
https://mybusinessqanda.googleapis.com
Business Profile Performance API
(9)- Google のビジネス プロフィールのパフォーマンス レポートを取得するためのインターフェース
- サービスエンドポイント
https://businessprofileperformance.googleapis.com
Method: locations.getDailyMetricsTimeSeries
Method: locations.fetchMultiDailyMetricsTimeSeries
Google マイビジネス v4.9 API
(10)- Google でビジネス情報を管理するためのインターフェース
- サービスエンドポイント
https://mybusiness.googleapis.com
ビジネスプロフィールマネージャ
- 管理画面
サポート終了スケジュール

ライブラリ
PHPクライアントライブラリ
Business Profile API系はこっち?(上のライブラリの一部としてインストールされるようだ)

サンプルコード
素のPHPにはなるが、Method: locations.fetchMultiDailyMetricsTimeSeriesを叩くサンプルコード
前提条件
集計対象となる店舗ID(locations/xxxxxxxx)が存在すること
事前準備
(1) composerのDL&セットアップ
# 開発用ディレクトリの作成
$ mkdir gbp_api && cd gbp_api
# composerのDL&セットアップ
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
$ php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
$ php composer-setup.php
$ php -r "unlink('composer-setup.php');"
# クライアントライブラリのインストール
composer require google/apiclient:^2.12.1
(2) APIキー、クライアントID等の発行
以下を参考に実施
①APIキー
②クライアントID, クライアントシークレット
③リフレッシュトークン
サンプルコード
fetchMultiDailyMetrics.php
<?php
namespace App\Service;
require_once __DIR__ . '/vendor/autoload.php';
$client = new \Google\Client();
$client->setClientId("クライアントIDを記入");
$client->setClientSecret("クライアントシークレットを記入");
// $client->setAccessType('offline');
$client->setApiFormatV2(true);
// $client->setRedirectUri('http://localhost:8000);
$client->addScope("https://www.googleapis.com/auth/business.manage");
$client->setDeveloperKey("デベロッパーキーを記入");
$accessToken = $client->fetchAccessTokenWithRefreshToken("リフレッシュトークンを記入");
$client->setAccessToken($accessToken);
$profilePerforService = new \Google\Service\BusinessProfilePerformance($client);
$locations = $profilePerforService->locations;
// 対象の店舗コードを記入
$location = 'locations/xxxxxxxxx';
$optParams = [
// 要素が複数の場合は配列、単数の場合はstringでOK
'dailyMetrics' => ['BUSINESS_DIRECTION_REQUESTS', 'CALL_CLICKS', 'BUSINESS_IMPRESSIONS_DESKTOP_MAPS'],
'dailyRange.startDate.day' => 25,
'dailyRange.startDate.month' => 3,
'dailyRange.startDate.year' => 2023,
'dailyRange.endDate.day' => 5,
'dailyRange.endDate.month' => 4,
'dailyRange.endDate.year' => 2023,
];
$result = $locations->fetchMultiDailyMetricsTimeSeries($location, $optParams);
var_dump($result);