GAPI クライアント ライブラリ

サーバー間(信頼できる)通信では、未加工の REST や gRPC で開発するよりも言語固有の GAPI クライアント ライブラリを使用することをおすすめします。これらのクライアントの基盤となる protobuf ファイルは、https://github.com/googleapis/googleapis/tree/master/google/maps/fleetengine/v1 で一般公開されています。

アプリケーションの言語にライブラリが存在しない場合は、gRPC または Fleet Engine REST エンドポイントを使用することをおすすめします。

注: GAPIC ライブラリは、信頼できる(サーバー)環境で実行することを想定しています。JWT は不要です。アプリケーションのデフォルト認証情報と適切な ondemandAdmin ロールを使用します。

Java

Java ライブラリは google.maps.fleetengine.v1 で公開されます。

Gradle

plugins {
  id "maven-publish"
  id "com.google.cloud.artifactregistry.gradle-plugin" version "2.1.4"
}

publishing {
  repositories {
    maven {
      url "artifactregistry://us-maven.pkg.dev/fleetengine-gapic/maven"
    }
  }
}

repositories {
  maven {
    url "artifactregistry://us-maven.pkg.dev/fleetengine-gapic/maven"
  }
}

dependencies {
  implementation 'com.google.maps:gapic-google-maps-fleetengine-v1-java:latest.release'
}

Maven

<project>
  <distributionManagement>
    <snapshotRepository>
      <id>artifact-registry</id>
      <url>artifactregistry://us-maven.pkg.dev/fleetengine-gapic/maven</url>
    </snapshotRepository>
    <repository>
      <id>artifact-registry</id>
      <url>artifactregistry://us-maven.pkg.dev/fleetengine-gapic/maven</url>
    </repository>
  </distributionManagement>

  <repositories>
    <repository>
      <id>artifact-registry</id>
      <url>artifactregistry://us-maven.pkg.dev/fleetengine-gapic/maven</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
  </repositories>

  <build>
    <extensions>
      <extension>
        <groupId>com.google.cloud.artifactregistry</groupId>
        <artifactId>artifactregistry-maven-wagon</artifactId>
        <version>2.1.4</version>
      </extension>
    </extensions>
  </build>

  <dependency>
    <groupId>com.google.maps</groupId>
    <artifactId>gapic-google-maps-fleetengine-v1-java</artifactId>
    <version>LATEST</version>
  </dependency>
</project>

Java 用 Fleet Engine Auth Library を使用して、Java 環境内で署名付き JSON ウェブトークンを作成できます。

Fleet Engine スタートガイドのページで、Fleet Engine API を操作する Java の例を確認できます。

Node.js / TypeScript

https://www.npmjs.com/package/@googlemaps/fleetengine をご覧ください。

npm

npm install @googlemaps/fleetengine

Go

Go ライブラリは、https://pkg.go.dev/maps/fleetengine/v1 でモジュールとしてパッケージ化されています。

package main

import (
    "context"
    "fmt"
    "log"

    "google.golang.org/api/iterator"
    "google.golang.org/api/option"
    fleetengine "google.golang.org/maps/fleetengine/v1"

    pb "google.golang.org/genproto/googleapis/maps/fleetengine/v1"
)

func main() {
    // Set the GOOGLE_APPLICATION_CREDENTIALS environment variable to point to a credential configuration file.
    // https://cloud.google.com/docs/authentication/application-default-credentials#GAC
    provider := "cabrio-1501793433270"

    ctx := context.Background()
    vc, err := fleetengine.NewVehicleClient(ctx,
        option.WithQuotaProject(provider),
        option.WithScopes("https://www.googleapis.com/auth/cloud-platform"),
    )
    if err != nil {
        log.Fatalf("Couldn't connect: %v", err)
    }

    i := vc.ListVehicles(ctx, &pb.ListVehiclesRequest{
        // NB: PageSize determines how many resources each call to the underlying
        // List method returns, not how many values the Iterator will go through.
        // The Iterator will continue making List calls until it exhausts
        // `nextPageToken`.
        PageSize: 10,
        Parent:   "providers/" + provider,
    })
    for {
        v, err := i.Next()
        if err == iterator.Done {
            break
        }
        if err != nil {
            log.Fatalf("Couldn't connect: %v", err)
        }
        fmt.Println(v)
    }
}

Python

https://pypi.org/project/google-maps-fleetengine/0.1.0/ をご覧ください。

pip

pip install google-auth
pip install google-maps-fleetengine

サンプルコード:

from google.maps import fleetengine_v1
import google.auth
from google.auth import jwt, iam
from google.auth.transport import requests

# CONSTANTS
PROJECT_ID = 'YOUR_GCP_PROJECT_NAME'
VEHICLE_ID = 'YOUR_VEHICLE_ID'
SERVICE_ACCOUNT = f'YOUR_SERVICE_ACCOUNT@{PROJECT_ID}.iam.gserviceaccount.com'

# CREATE A JWT FOR AUTHENTICATION
credentials, _ = google.auth.default(scopes=['https://www.googleapis.com/auth/iam'])
signer = iam.Signer(requests.Request(), credentials, SERVICE_ACCOUNT)
jwt_credentials = jwt.Credentials(
  signer,
  issuer=SERVICE_ACCOUNT,
  subject=SERVICE_ACCOUNT,
  audience='https://fleetengine.googleapis.com/',
  additional_claims={
    "authorization": {
      "vehicleid" : VEHICLE_ID
    }
  }
)

# MAKE A REQUEST
maps_fleetengine_client = fleetengine_v1.VehicleServiceClient(credentials=jwt_credentials)
request = fleetengine_v1.GetVehicleRequest(name=f'providers/{PROJECT_ID}/vehicles/{VEHICLE_ID}')
response = maps_fleetengine_client.get_vehicle(request=request)

C#

C# ライブラリのインストール手順については、https://www.nuget.org/packages/Google.Maps.FleetEngine.V1 をご覧ください。

PHP

https://packagist.org/packages/google/maps-fleetengine をご覧ください。

Ruby

https://rubygems.org/gems/google-maps-fleet_engine をご覧ください。