Googleapis 服务帐号认证 Gaxios 错误

问题描述

我在使用 Google Play Developer API 的购买验证过程中遇到了一些问题。 更准确地说,介于 JWT 令牌的生成和使用之间。

private androidpublisher: any = google.androidpublisher({
  version: 'v3',});

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

public async getSubscriptionPurchaseInfo(
  packageName: string,subscriptionId: string,token: string,): Promise<any> {
  try {
    await this.authClient.authorize();
    return this.androidpublisher.purchases.subscriptions.get({
      auth: this.authClient,packageName,subscriptionId,token,});
  } catch ( error ) {
    throw new GoogleApiAuthenticationException(error.message);
  }

}

我得到的错误 -->

[nest] 212   - 01/27/2021,4:28:47 PM   [ExceptionsHandler] Invalid Value +913254ms
Error: Invalid Value
     at Gaxios._request (/app/node_modules/gaxios/build/src/gaxios.js:112:23)
     at processticksAndRejections (internal/process/task_queues.js:93:5)
     at async JWT.requestAsync (/app/node_modules/google-auth-library/build/src/auth/oauth2client.js:343:18)

在我看来,错误是在尝试生成 JWT 令牌和使用它之间的某个地方产生的。

我也试过 -->

const auth = new google.auth.GoogleAuth({
  keyFile: '/path/to/your-secret-key.json',scopes: ['https://www.googleapis.com/auth/cloud-platform'],});

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)