问题描述
我正在尝试向 google 发出请求以验证我的 IAP 购买,但我不断收到错误消息
Gaxios._request 的值无效 (/srv/node_modules/googleapis-common/node_modules/gaxios/build/src/gaxios.js:89:23)
我记录了这些值,它们似乎是正确的值.购买本身在我的应用程序中运行,只是我无法在服务器上验证它.如何查看无效值是什么?
异步函数 verifySubscriptionAndroid(purchase: InAppPurchaseModel): Promise;{让状态;console.log(packageName);//com.company.my_app_name 但它是我的实际应用程序名称console.log(purchase.id);//7162541432 这是我在 google play 控制台中提供给订阅的 idconsole.log(purchase.token);//fdlidklhmmfggackclaedklj.AO-J1Ozu3HBDHN3BqTconVT8pMfvVIi_Iw9nIaY6t5Datphb62ehBJuHwFYXKmAw2VZafChN1fmrbY6_6bdh_-Fzq0Is3-e3u829-ckImdMT9gijDVCkC4mL1kWxqtJ5pWHVNb尝试 {等待 authClient.authorize();常量订阅 = 等待 playDeveloperApiClient.purchases.subscriptions.get({包名:包名,subscriptionId: purchase.id,代币:purchase.token});状态 = 订阅状态;} 捕捉(错误){控制台日志(错误)}返回状态 === 200;};
这是我的模特
导出类 IAPReceiptModel {来源:字符串;标识:字符串;令牌:字符串;isSubscription:布尔值;构造函数(来源:字符串,productId:字符串,令牌:字符串,isSubscription:布尔值){this.source = 来源;this.id = productId;this.token=令牌;this.isSubscription = isSubscription;}静态 fromJSON(数据:任何):IAPReciptModel {控制台.log(数据);常量源:字符串 = 数据?.源?'';const productId: string = data?.id ??'';常量令牌:字符串=数据?.令牌??'';const isSubscription:boolean = data?.isSubscription ??错误的;return new IAPReceiptModel(source, productId, verifyData, isSubscription);}}
我正在使用 google Auth api
从 'googleapis' 导入 { google };从 './keys/service_account_key.json' 导入 * 作为密钥;const authClient = 新的 google.auth.JWT({电子邮件:key.client_email,密钥:key.private_key,范围:[https://www.googleapis.com/auth/androidpublisher"]});常量 playDeveloperApiClient = google.androidpublisher({版本:'v3',身份验证:authClient});
我有一个服务帐户设置.
它正在向以下网址发出请求
https://www.googleapis.com/androidpublisher/v3/applications/com.company.my_app_name/purchases/products/7162541432/tokens/fdlidklhmmfggackclaedklj.AO-J1Ozu3HBDHN3BqTconVT8pMfvVIi_Iw9nIaY6t5Datphb62ehBJuHwFYXKmAw2VZafChN1fmrbY6_6bdh_-Fzq0Is3-e3u829-ckImdMT9gijDVCkC4mL1kWxqtJ5pWHVNbAIzGz_注意:我在问题中更改了包名、sku_id 和令牌,但他们已签出
我看过
I am trying to make a request to the google to verify my IAP purchase but I keep getting the error
Invalid Value at Gaxios._request (/srv/node_modules/googleapis-common/node_modules/gaxios/build/src/gaxios.js:89:23)
I logged the values and they seem to be the correct values. The purchase itself is working in my app it's just that I can't verify it on the server. How can I see what the invalid value is?
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;
};
This is my model
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);
}
}
I am using the google Auth api
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
});
And I have a service account setup.
It is making a request to the following 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_
Note: I changed the packagename, sku_id and token in my question but they check out
I looked at
Verify a Purchase using Firebase Functions
for reference and also tried to inject the authclient directly into the object like
const response = await playDeveloperApiClient.purchases.subscriptions.get({
auth: authClient,
packageName: packageName,
subscriptionId: receipt.productId,
token: receipt.verificationData
});
Maybe you want to try initializing the Google API like this:
const playDeveloperApiClient = google.androidpublisher('v3');
And add auth
to:
const subscription = await playDeveloperApiClient.purchases.subscriptions.get({
auth: authClient,
packageName: packageName,
subscriptionId: purchase.id,
token: purchase.token
});
For the purchase.id
I find it odd that you are using a number for the Id, ideally you would want to put a string as I mentioned in the comments, just in case, it should be the Product ID in your Subscriptions section in the Play Console as highlighted in the picture below:
这篇关于Gaxios._request 中的值无效 (/srv/node_modules/googleapis-common/node_modules/gaxios/build/src/gaxios.js:89:23)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!