Open3

Google Business Profile APIs

ChiHaRuChiHaRu

公式サイト

概要

https://developers.google.com/my-business/ref_overview

Business Profile自体の概要は以下を参照
https://developers.google.com/my-business/content/overview

Business Profileに関する様々な情報は以下を参照
https://support.google.com/business/

APIの種類と役割

(1) Account Management API

(2) Business Calls API

  • Google 上のビジネス情報のビジネス電話に関する情報を管理し、ビジネス拠点への不在着信の件数などの分析情報を収集
  • サービスエンドポイント
    https://mybusinessbusinesscalls.googleapis.com

(3) Lodging API

(4) Place Actions API

(5) Notifications API

(6) Verifications API

(7) Business Information API

(8) Q&A API

(9) Business Profile Performance API

Method: locations.getDailyMetricsTimeSeries

https://developers.google.com/my-business/reference/performance/rest/v1/locations/getDailyMetricsTimeSeries

Method: locations.fetchMultiDailyMetricsTimeSeries

https://developers.google.com/my-business/reference/performance/rest/v1/locations/fetchMultiDailyMetricsTimeSeries

(10) Google マイビジネス v4.9 API

ビジネスプロフィールマネージャ

  • 管理画面

サポート終了スケジュール

ChiHaRuChiHaRu

サンプルコード

素の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キー
https://developers.google.com/maps/documentation/javascript/get-api-key?hl=ja
②クライアントID, クライアントシークレット
https://developers.google.com/my-business/content/basic-setup?hl=ja#request-client-id
③リフレッシュトークン
https://cloud.google.com/apigee/docs/api-platform/security/oauth/access-tokens?hl=ja

サンプルコード

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);