GAPI 클라이언트 라이브러리

서버 간 (신뢰할 수 있는) 통신의 경우 원시 REST 또는 gRPC를 통해 개발하는 것보다 더 나은 환경을 위해 언어별 GAPI 클라이언트 라이브러리를 사용하는 것이 좋습니다. 이러한 클라이언트의 기반이 되는 protobuf 파일은 https://github.com/googleapis/googleapis/tree/master/google/maps/fleetengine/delivery/v1에서 공개적으로 제공됩니다.

애플리케이션이 사용하는 언어로 라이브러리가 없으면 gRPC 또는 Fleet Engine REST 엔드포인트를 사용하는 것이 좋습니다.

참고: GAPIC 라이브러리는 신뢰할 수 있는 (서버) 환경에서 실행되도록 고안되었습니다. JWT는 필요하지 않습니다. 애플리케이션 기본 사용자 인증 정보를 적절한 deliveryAdmin 역할과 함께 사용합니다.

Java

자바 라이브러리는 google.maps.fleetengine.delivery.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-delivery-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-delivery-v1-java</artifactId>
    <version>LATEST</version>
  </dependency>
</project>

Java용 Fleet Engine 인증 라이브러리를 활용하여 자바 환경 내에서 서명된 JSON 웹 토큰을 만들 수 있습니다.

Fleet Engine 시작하기 페이지에서 Fleet Engine API와 상호작용하기 위한 자바 예시를 확인할 수 있습니다.

Node.js / TypeScript

npm

package.jsondependencies 섹션에서 라이브러리 URL을 지정할 수 있습니다.

{
  "dependencies": {
    "@googlemaps/fleetengine-delivery": "https://storage.googleapis.com/fleetengine-gapic/dist/latest_release/maps-fleetengine-delivery-v1-nodejs.tar.gz",
    "google-auth-library": "^9.2.0",
    "googleapis": "^118.0.0"
  }
}

샘플 코드

const {google} = require('googleapis');
const fleetengine = require('@googlemaps/fleetengine-delivery');
const {GoogleAuth} = require('google-auth-library');

// CONSTANTS
const PROJECT_ID = 'YOUR_GCP_PROJECT_NAME';
const VEHICLE_ID = 'YOUR_VEHICLE_ID';
const SERVICE_ACCOUNT = 'YOUR_SERVICE_ACCOUNT';
const SERVICE_ACCOUNT_EMAIL = `${SERVICE_ACCOUNT}@${PROJECT_ID}.iam.gserviceaccount.com`;

// CREATE A JWT FOR AUTHENTICATION
const HOWLONG = 55 * 60;          // 55 minutes, cannot be more than 60 minutes

async function signToken(claims) {
  const googleAuth = new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  });
  const authClient = await googleAuth.getClient();
  google.options({auth: authClient});

  const now = Math.round(Date.now() / 1000);
  const iat = now - 300;
  const exp = now + HOWLONG;

  const request = {
      name: `projects/-/serviceAccounts/${SERVICE_ACCOUNT_EMAIL}`,
      requestBody: {
          payload: JSON.stringify({
              iss: SERVICE_ACCOUNT_EMAIL,
              sub: SERVICE_ACCOUNT_EMAIL,
              aud: 'https://fleetengine.googleapis.com/',
              iat: iat,
              exp: exp,
              authorization: claims
          }),
      }
  };

  const response = await google.iamcredentials('v1').projects.serviceAccounts
      .signJwt(request)
      .catch((err) => {
        if (err.errors) throw err.errors;
        else throw err;
      });
  return response.data.signedJwt;
}

// MAKE A REQUEST
async function main() {
    const claims = {
      deliveryvehicleid: VEHICLE_ID
    };

    signToken(claims).then(token => {
      let auth = new GoogleAuth();
      auth.cachedCredential = new AuthorizationHeaderProvider(token);
      const client = new fleetengine.DeliveryServiceClient({ auth: auth });

      client.getDeliveryVehicle({name: `providers/${PROJECT_ID}/deliveryVehicles/${VEHICLE_ID}`}).then(function(resp) {
        console.log(resp);
      }, function(err) {
        console.log(err);
      });
    });
}

class AuthorizationHeaderProvider {
    constructor(token) {
        this.token = token;
    }

    getRequestMetadata(url, callback) {
        callback(null, {'authorization': `Bearer ${this.token}`});
    }
}

main().catch(console.error);

Go

Go 라이브러리는 https://pkg.go.dev/cloud.google.com/go/maps에서 모듈로 패키징됩니다.

Python

https://pypi.org/project/google-maps-fleetengine-delivery/0.1.0/을 참고하세요.

pip

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

C#

C# 라이브러리 설치 안내는 https://www.nuget.org/packages/Google.Maps.FleetEngine.Delivery.V1에서 확인할 수 있습니다.

2,399필리핀

PHP 라이브러리는 https://storage.googleapis.com/fleetengine-gapic/dist/latest_release/google-maps-fleetengine-delivery-v1-php.tar.gz에서 다운로드할 수 있습니다.

Ruby

https://rubygems.org/gems/google-maps-fleet_engine-delivery를 참고하세요.