GAPI ক্লায়েন্ট লাইব্রেরি

সার্ভার-টু-সার্ভার (বিশ্বস্ত) যোগাযোগের জন্য, আমরা কাঁচা REST বা gRPC-এর চেয়ে উন্নত অভিজ্ঞতার জন্য ভাষা-নির্দিষ্ট GAPI ক্লায়েন্ট লাইব্রেরি ব্যবহার করার পরামর্শ দিই। এই ক্লায়েন্টদের উপর ভিত্তি করে প্রোটোবাফ ফাইলগুলি সর্বজনীনভাবে https://github.com/googleapis/googleapis/tree/master/google/maps/fleetengine/v1 এ উপলব্ধ।

আপনার অ্যাপ্লিকেশনের ভাষায় লাইব্রেরি না থাকলে, আমরা gRPC বা Fleet Engine REST এন্ডপয়েন্ট ব্যবহার করার পরামর্শ দিই।

দ্রষ্টব্য: GAPIC লাইব্রেরি বিশ্বস্ত (সার্ভার) পরিবেশে চালানোর জন্য বোঝানো হয়। JWTs অপ্রয়োজনীয়। উপযুক্ত ondemandAdmin ভূমিকা সহ অ্যাপ্লিকেশন ডিফল্ট শংসাপত্রগুলি ব্যবহার করুন৷

জাভা

জাভা লাইব্রেরি google.maps.fleetengine.v1 এর অধীনে প্রকাশিত হয়।

গ্রেডল

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'
}

মাভেন

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

আপনি জাভা পরিবেশের মধ্যে স্বাক্ষরিত JSON ওয়েব টোকেন তৈরি করতে জাভার জন্য ফ্লিট ইঞ্জিন প্রমাণীকরণ লাইব্রেরি ব্যবহার করতে পারেন।

আপনি ফ্লিট ইঞ্জিন এপিআই এর সাথে ইন্টারঅ্যাক্ট করার জন্য ফ্লিট ইঞ্জিনের সাথে শুরু করার পৃষ্ঠায় জাভা উদাহরণ দেখতে পারেন।

Node.js / TypeScript

npm

আপনি package.json এর dependencies বিভাগে লাইব্রেরি URL উল্লেখ করতে পারেন:

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

কোডের উদাহরণ:

const {google} = require('googleapis');
const fleetengine = require('@googlemaps/fleetengine');
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 = {
      vehicleid: VEHICLE_ID
    };

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

      client.getVehicle({name: `providers/${PROJECT_ID}/vehicles/${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 লাইব্রেরিটি 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)
    }
}

পাইথন

https://pypi.org/project/google-maps-fleetengine/0.1.0/ দেখুন

পিপ

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# লাইব্রেরির জন্য ইনস্টলেশন নির্দেশাবলী https://www.nuget.org/packages/Google.Maps.FleetEngine.V1 এ পাওয়া যাবে।

পিএইচপি

PHP লাইব্রেরি https://storage.googleapis.com/fleetengine-gapic/dist/latest_release/google-maps-fleetengine-v1-php.tar.gz থেকে ডাউনলোড করা যেতে পারে

রুবি

https://rubygems.org/gems/google-maps-fleet_engine দেখুন।