Gaxios._request处的值无效(/srv/node_modules/googleapis-common/node_modules/gaxios/build/src/gaxios.js:89:23) [英] Invalid Value at Gaxios._request (/srv/node_modules/googleapis-common/node_modules/gaxios/build/src/gaxios.js:89:23)
问题描述
我正在尝试向Google发出请求,以验证我的IAP购买,但我不断收到错误消息
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;
};
这是我的模特
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);
}
}
我正在使用Google Auth api
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.
它正在请求以下网址
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和令牌,但它们已签出
Note: I changed the packagename, sku_id and token in my question but they check out
我看着
供参考,还尝试将authclient直接注入到对象中,例如
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
});
推荐答案
也许您想尝试像这样初始化Google API:
Maybe you want to try initializing the Google API like this:
const playDeveloperApiClient = google.androidpublisher('v3');
并将auth
添加到:
const subscription = await playDeveloperApiClient.purchases.subscriptions.get({
auth: authClient,
packageName: packageName,
subscriptionId: purchase.id,
token: purchase.token
});
对于purchase.id
,我发现您使用数字作为ID很奇怪,理想情况下,您希望像我在注释中提到的那样放置一个字符串,以防万一,它应该是产品ID 在Play控制台的订阅"部分中,如下图所示:
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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!