Valore non valido in Gaxios._request (/srv/node_modules/googleapis-common/node_modules/gaxios/build/src/gaxios.js:89:23)

Sep 30 2020

Sto provando a fare una richiesta a Google per verificare il mio acquisto IAP ma continuo a ricevere l'errore

Invalid Value at Gaxios._request (/srv/node_modules/googleapis-common/node_modules/gaxios/build/src/gaxios.js:89:23)

Ho registrato i valori e sembrano essere i valori corretti. L'acquisto stesso funziona nella mia app, è solo che non posso verificarlo sul server. Come posso vedere qual è il valore non valido?

async function verifySubscriptionAndroid(purchase: InAppPurchaseModel): Promise<boolean> {
    let status;
    console.log(packageName); //com.company.my_app_name but then it is my actual app name in that format
    console.log(purchase.id); //7162541432 which is the id I provided to the subscription in the google play console
    console.log(purchase.token); //fdlidklhmmfggackclaedklj.AO-J1Ozu3HBDHN3BqTconVT8pMfvVIi_Iw9nIaY6t5Datphb62ehBJuHwFYXKmAw2VZafChN1fmrbY6_6bdh_-Fzq0Is3-e3u829-ckImdMT9gijDVCkC4mL1kWxqtJ5pWHVNbAIzGz_

    try {
        await authClient.authorize();
        const subscription = await playDeveloperApiClient.purchases.subscriptions.get({
            packageName: packageName, 
            subscriptionId: purchase.id,
            token: purchase.token
        });
        status = subscription.status;
    } catch (error) {
        console.log(error)
    }
    return status === 200;
};

Questo è il mio modello

export class IAPReceiptModel {
    source: string;
    id:string;
    token: string;
    isSubscription: boolean;


    constructor(source: string, productId:string, token: string, isSubscription: boolean) {
        this.source = source;
        this.id = productId;
        this.token= token;
        this.isSubscription = isSubscription;
    }

    static fromJSON(data: any): IAPReceiptModel {
        console.log(data);
        const source: string = data?.source ?? '';
        const productId: string = data?.id ?? '';
        const token: string = data?.token ?? '';
        const isSubscription:boolean = data?.isSubscription ?? false;
        return new IAPReceiptModel(source, productId, verificationData, isSubscription);
    }
}

Sto usando l'API di Google Auth

import { google } from 'googleapis';
import * as key from './keys/service_account_key.json';

const authClient = new google.auth.JWT({
    email: key.client_email,
    key: key.private_key,
    scopes: ["https://www.googleapis.com/auth/androidpublisher"]
});

const playDeveloperApiClient = google.androidpublisher({
    version: 'v3',
    auth: authClient
});

E ho configurato un account di servizio.

Sta effettuando una richiesta al seguente URL

https://www.googleapis.com/androidpublisher/v3/applications/com.company.my_app_name/purchases/products/7162541432/tokens/fdlidklhmmfggackclaedklj.AO-J1Ozu3HBDHN3BqTconVT8pMfvVIi_Iw9nIaY6t5Datphb62ehBJuHwFYXKmAw2VZafChN1fmrbY6_6bdh_-Fzq0Is3-e3u829-ckImdMT9gijDVCkC4mL1kWxqtJ5pWHVNbAIzGz_

Nota: ho cambiato il nome del pacchetto, lo sku_id e il token nella mia domanda, ma hanno verificato

Ho guardato

Verifica un acquisto utilizzando le funzioni Firebase

per riferimento e ho anche provato a iniettare il client di autenticazione direttamente nell'oggetto come

const response = await playDeveloperApiClient.purchases.subscriptions.get({
    auth: authClient,
    packageName: packageName,
    subscriptionId: receipt.productId,
    token: receipt.verificationData
});

Risposte

Racu Oct 01 2020 at 10:07

Forse vuoi provare a inizializzare l'API di Google in questo modo:

const playDeveloperApiClient = google.androidpublisher('v3');

E aggiungi autha:

const subscription = await playDeveloperApiClient.purchases.subscriptions.get({
                auth: authClient,
                packageName: packageName, 
                subscriptionId: purchase.id,
                token: purchase.token
            });

Per il purchase.idtrovo strano che tu stia usando un numero per l'ID, idealmente vorresti mettere una stringa come ho detto nei commenti, per ogni evenienza, dovrebbe essere l' ID prodotto nella sezione Iscrizioni nella Play Console come evidenziato nella foto sotto: