Google Wallet API-তে অনুরোধগুলি প্রমাণীকরণ করুন৷

Google Wallet API-এর অনুরোধগুলি অবশ্যই প্রমাণীকৃত হতে হবে যাতে Wallet API সনাক্ত করতে পারে যে অনুরোধটি আপনার অ্যাপ্লিকেশন দ্বারা করা হচ্ছে৷

আপনি শুরু করার আগে, নিশ্চিত করুন যে আপনি Google Wallet REST API এবং Google Wallet Android SDK- এর জন্য আপনার শংসাপত্রগুলি সঠিকভাবে তৈরি এবং নিবন্ধিত করেছেন৷

Google Wallet REST API অনুরোধ

একটি অ্যাক্সেস টোকেন পাওয়ার জন্য Google Wallet REST API Google Wallet REST API Google ক্লাউড পরিষেবা অ্যাকাউন্ট কী ব্যবহার করে Google Wallet REST API-এর অনুরোধ প্রমাণিত হয়।

Google API ক্লায়েন্ট লাইব্রেরিগুলি প্রমাণীকরণ এবং API অনুরোধগুলি পরিচালনা করে। নিশ্চিত করুন যে আপনি আপনার পছন্দের প্রোগ্রামিং ভাষার জন্য লাইব্রেরি ইনস্টল করেছেন, যা নিম্নলিখিত উদাহরণগুলি ব্যবহার করে।

প্রথমে, প্রয়োজনীয় লাইব্রেরি আমদানি সম্পাদন করুন এবং JSON পরিষেবা অ্যাকাউন্টের জন্য কিছু ভেরিয়েবল এবং ইস্যুকারী, শ্রেণী, অনন্য ব্যবহারকারী এবং অবজেক্টের জন্য আইডি সংজ্ঞায়িত করুন যা সংরক্ষণ করা হবে।

জাভা

জাভাতে আপনার ইন্টিগ্রেশন শুরু করতে, GitHub-এ আমাদের সম্পূর্ণ কোড নমুনা পড়ুন।

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.google.api.client.googleapis.batch.BatchRequest;
import com.google.api.client.googleapis.batch.json.JsonBatchCallback;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.googleapis.json.GoogleJsonError;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.*;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.walletobjects.*;
import com.google.api.services.walletobjects.model.*;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.auth.oauth2.ServiceAccountCredentials;
import java.io.*;
import java.security.interfaces.RSAPrivateKey;
import java.util.*;

/** Demo class for creating and managing Offers in Google Wallet. */
public class DemoOffer {
  /**
   * Path to service account key file from Google Cloud Console. Environment variable:
   * GOOGLE_APPLICATION_CREDENTIALS.
   */
  public static String keyFilePath;

  /** Service account credentials for Google Wallet APIs. */
  public static GoogleCredentials credentials;

  /** Google Wallet service client. */
  public static Walletobjects service;

  public DemoOffer() throws Exception {
    keyFilePath =
        System.getenv().getOrDefault("GOOGLE_APPLICATION_CREDENTIALS", "/path/to/key.json");

    auth();
  }

পিএইচপি

PHP-তে আপনার ইন্টিগ্রেশন শুরু করতে, GitHub-এ আমাদের সম্পূর্ণ কোড নমুনা দেখুন।

use Firebase\JWT\JWT;
use Google\Auth\Credentials\ServiceAccountCredentials;
use Google\Client as GoogleClient;
use Google\Service\Walletobjects;
use Google\Service\Walletobjects\DateTime;
use Google\Service\Walletobjects\TimeInterval;
use Google\Service\Walletobjects\OfferObject;
use Google\Service\Walletobjects\OfferClass;
use Google\Service\Walletobjects\LatLongPoint;
use Google\Service\Walletobjects\Barcode;
use Google\Service\Walletobjects\ImageModuleData;
use Google\Service\Walletobjects\LinksModuleData;
use Google\Service\Walletobjects\TextModuleData;
use Google\Service\Walletobjects\TranslatedString;
use Google\Service\Walletobjects\LocalizedString;
use Google\Service\Walletobjects\ImageUri;
use Google\Service\Walletobjects\Image;
use Google\Service\Walletobjects\Message;
use Google\Service\Walletobjects\AddMessageRequest;
use Google\Service\Walletobjects\Uri;

/** Demo class for creating and managing Offers in Google Wallet. */
class DemoOffer
{
  /**
   * The Google API Client
   * https://github.com/google/google-api-php-client
   */
  public GoogleClient $client;

  /**
   * Path to service account key file from Google Cloud Console. Environment
   * variable: GOOGLE_APPLICATION_CREDENTIALS.
   */
  public string $keyFilePath;

  /**
   * Service account credentials for Google Wallet APIs.
   */
  public ServiceAccountCredentials $credentials;

  /**
   * Google Wallet service client.
   */
  public Walletobjects $service;

  public function __construct()
  {
    $this->keyFilePath = getenv('GOOGLE_APPLICATION_CREDENTIALS') ?: '/path/to/key.json';

    $this->auth();
  }

পাইথন

পাইথনে আপনার ইন্টিগ্রেশন শুরু করতে, GitHub-এ আমাদের সম্পূর্ণ কোড নমুনা দেখুন।

import json
import os
import uuid

from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from google.oauth2.service_account import Credentials
from google.auth import jwt, crypt


class DemoOffer:
    """Demo class for creating and managing Offers in Google Wallet.

    Attributes:
        key_file_path: Path to service account key file from Google Cloud
            Console. Environment variable: GOOGLE_APPLICATION_CREDENTIALS.
        base_url: Base URL for Google Wallet API requests.
    """

    def __init__(self):
        self.key_file_path = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS',
                                            '/path/to/key.json')
        # Set up authenticated client
        self.auth()

সি#

C# এ আপনার ইন্টিগ্রেশন শুরু করতে, GitHub-এ আমাদের সম্পূর্ণ কোড নমুনাগুলি পড়ুন।

using System.IdentityModel.Tokens.Jwt;
using System.Net.Http.Headers;
using System.Text.RegularExpressions;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Walletobjects.v1;
using Google.Apis.Walletobjects.v1.Data;
using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;


/// <summary>
/// Demo class for creating and managing Offers in Google Wallet.
/// </summary>
class DemoOffer
{
  /// <summary>
  /// Path to service account key file from Google Cloud Console. Environment
  /// variable: GOOGLE_APPLICATION_CREDENTIALS.
  /// </summary>
  public static string keyFilePath;

  /// <summary>
  /// Service account credentials for Google Wallet APIs
  /// </summary>
  public static ServiceAccountCredential credentials;

  /// <summary>
  /// Google Wallet service client
  /// </summary>
  public static WalletobjectsService service;

  public DemoOffer()
  {
    keyFilePath = Environment.GetEnvironmentVariable(
        "GOOGLE_APPLICATION_CREDENTIALS") ?? "/path/to/key.json";

    Auth();
  }

Node.js

নোডে আপনার ইন্টিগ্রেশন শুরু করতে, GitHub-এ আমাদের সম্পূর্ণ কোড নমুনা পড়ুন।

const { google } = require('googleapis');
const jwt = require('jsonwebtoken');
const { v4: uuidv4 } = require('uuid');

/**
 * Demo class for creating and managing Offers in Google Wallet.
 */
class DemoOffer {
  constructor() {
    /**
     * Path to service account key file from Google Cloud Console. Environment
     * variable: GOOGLE_APPLICATION_CREDENTIALS.
     */
    this.keyFilePath = process.env.GOOGLE_APPLICATION_CREDENTIALS || '/path/to/key.json';
    this.auth();
  }

যাওয়া

Go-তে আপনার ইন্টিগ্রেশন শুরু করতে, GitHub-এ GitHub কোড নমুনাগুলিতে আমাদের সম্পূর্ণ কোড নমুনা দেখুন।

package main

import (
	"bytes"
	"context"
	"encoding/json"
	"fmt"
	"github.com/golang-jwt/jwt"
	"github.com/google/uuid"
	"golang.org/x/oauth2"
	"golang.org/x/oauth2/google"
	oauthJwt "golang.org/x/oauth2/jwt"
	"google.golang.org/api/option"
	"google.golang.org/api/walletobjects/v1"
	"io"
	"log"
	"os"
	"strings"
)

এরপরে, Google Wallet API কল করার জন্য প্রয়োজনীয় শংসাপত্রগুলি পুনরুদ্ধার করতে ফ্রেমওয়ার্ক লাইব্রেরিগুলির একটি ব্যবহার করুন৷

জাভা

জাভাতে আপনার ইন্টিগ্রেশন শুরু করতে, GitHub-এ আমাদের সম্পূর্ণ কোড নমুনা পড়ুন।

/**
 * Create authenticated HTTP client using a service account file.
 *
 */
public void auth() throws Exception {
  credentials =
      GoogleCredentials.fromStream(new FileInputStream(keyFilePath))
          .createScoped(List.of(WalletobjectsScopes.WALLET_OBJECT_ISSUER));
  credentials.refresh();

  HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();

  // Initialize Google Wallet API service
  service =
      new Walletobjects.Builder(
              httpTransport,
              GsonFactory.getDefaultInstance(),
              new HttpCredentialsAdapter(credentials))
          .setApplicationName("APPLICATION_NAME")
          .build();
}

পিএইচপি

PHP-তে আপনার ইন্টিগ্রেশন শুরু করতে, GitHub-এ আমাদের সম্পূর্ণ কোড নমুনা দেখুন।

/**
 * Create authenticated HTTP client using a service account file.
 */
public function auth()
{
  $this->credentials = new ServiceAccountCredentials(
    Walletobjects::WALLET_OBJECT_ISSUER,
    $this->keyFilePath
  );

  // Initialize Google Wallet API service
  $this->client = new GoogleClient();
  $this->client->setApplicationName('APPLICATION_NAME');
  $this->client->setScopes(Walletobjects::WALLET_OBJECT_ISSUER);
  $this->client->setAuthConfig($this->keyFilePath);

  $this->service = new Walletobjects($this->client);
}

পাইথন

পাইথনে আপনার ইন্টিগ্রেশন শুরু করতে, GitHub-এ আমাদের সম্পূর্ণ কোড নমুনা দেখুন।

def auth(self):
    """Create authenticated HTTP client using a service account file."""
    self.credentials = Credentials.from_service_account_file(
        self.key_file_path,
        scopes=['https://www.googleapis.com/auth/wallet_object.issuer'])

    self.client = build('walletobjects', 'v1', credentials=self.credentials)

সি#

C# এ আপনার ইন্টিগ্রেশন শুরু করতে, GitHub-এ আমাদের সম্পূর্ণ কোড নমুনাগুলি পড়ুন।

/// <summary>
/// Create authenticated service client using a service account file.
/// </summary>
public void Auth()
{
  credentials = (ServiceAccountCredential)GoogleCredential
      .FromFile(keyFilePath)
      .CreateScoped(new List<string>
      {
        WalletobjectsService.ScopeConstants.WalletObjectIssuer
      })
      .UnderlyingCredential;

  service = new WalletobjectsService(
      new BaseClientService.Initializer()
      {
        HttpClientInitializer = credentials
      });
}

Node.js

নোডে আপনার ইন্টিগ্রেশন শুরু করতে, GitHub-এ আমাদের সম্পূর্ণ কোড নমুনা পড়ুন।

/**
 * Create authenticated HTTP client using a service account file.
 */
auth() {
  const auth = new google.auth.GoogleAuth({
    keyFile: this.keyFilePath,
    scopes: ['https://www.googleapis.com/auth/wallet_object.issuer'],
  });

  this.credentials = require(this.keyFilePath);

  this.client = google.walletobjects({
    version: 'v1',
    auth: auth,
  });
}

যাওয়া

Go-তে আপনার ইন্টিগ্রেশন শুরু করতে, GitHub-এ GitHub কোড নমুনাগুলিতে আমাদের সম্পূর্ণ কোড নমুনা দেখুন।

// Create authenticated HTTP client using a service account file.
func (d *demoOffer) auth() {
	credentialsFile := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
	b, _ := os.ReadFile(credentialsFile)
	credentials, err := google.JWTConfigFromJSON(b, walletobjects.WalletObjectIssuerScope)
	if err != nil {
		fmt.Println(err)
		log.Fatalf("Unable to load credentials: %v", err)
	}
	d.credentials = credentials
	d.service, _ = walletobjects.NewService(context.Background(), option.WithCredentialsFile(credentialsFile))
}

Google Wallet Android SDK অনুরোধ

Google Wallet Android SDK ব্যবহার করে অনুরোধগুলি আপনার অ্যাপ সাইনিং শংসাপত্র ব্যবহার করে স্বয়ংক্রিয়ভাবে প্রমাণীকৃত হয়। Android SDK স্বয়ংক্রিয়ভাবে আপনার স্বাক্ষর শংসাপত্রের SHA-1 আঙ্গুলের ছাপ তৈরি করবে এবং Google Wallet API-তে অনুরোধের সাথে এটি অন্তর্ভুক্ত করবে।

আপনার অ্যাপ সাইনিং সার্টিফিকেটের SHA-1 ফিঙ্গারপ্রিন্ট তৈরি এবং নিবন্ধন করার বিষয়ে আরও তথ্যের জন্য, Google Wallet Android SDK-এর জন্য আপনার অ্যাপ অনুমোদন করা দেখুন।