Googleapis 服务帐号认证 Gaxios 错误

时间:2021-02-22 16:12:04

标签: google-authentication google-api-client google-api-nodejs-client

我在使用 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'],
});

0 个答案:

没有答案