google-api-nodejs-client icon indicating copy to clipboard operation
google-api-nodejs-client copied to clipboard

"Invalid Credentials" error trying to validate an android Purchase

Open GuanacoDevs opened this issue 7 years ago • 2 comments

Environment details

  • OS: Linux with Code
  • Node.js version: v10.14.2
  • npm version: 6.4.1
  • googleapis version: 32.0.0

Steps to reproduce

  1. Hi, I have been validating inapp purchases using the following with Firebase Functions
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const {google} = require("googleapis");
const publisher = google.androidpublisher('v2');
const authClient = new google.auth.JWT({
    email: 'Service Account Email',
    key: '-----BEGIN PRIVATE KEY-----\n**********************************************************************************==\n-----END PRIVATE KEY-----\n',
    scopes: ['https://www.googleapis.com/auth/androidpublisher']
});
admin.initializeApp();

exports.validatePurchases = functions.database
    .ref('/purchases/{uId}/{orderId}')
    .onCreate((event, context) => {
        const purchase = event.val();
        if (purchase.is_processed === true) {
            console.log('Purchase already processed!, exiting');
            return null;
        }
        const orderId = context.params.orderId;
        const dbRoot = event.ref.root;
        const package_name = purchase.package_name;
        const sku = purchase.sku;
        const my_token = purchase.token;

        authClient.authorize((err, result) => {
            if (err) {
                console.log(err);
            }
            publisher.purchases.products.get({
                auth: authClient,
                packageName: package_name,
                productId: sku,
                token: my_token
            }, (err, response) => {
                if (err) {
                    console.log(err);
                }
                // Result Status must be equals to 200 so that the purchase is valid
                if (response.status === 200) {
                    return event.ref.child('is_validated').set(true);
                } else {
                    return event.ref.child('is_validated').set(false);
                }
            });
        });
        return null;
    });

But now the same is giving me Invalid Credentials error, this happened when I try to make the same function using Promises. At some point I was calling two different functions during testing and an error with this message appeared in my logs: "code":10,"message":"An operation on function validatePurchases in region us-central1 in project *********** is already in progress. Please try again later."

I tried creating a new service account but still the error of Invalid Credentials persists.

What can be the cause of this error, the function was working really good before I tried to switch to Promises.

EDIT: Also if I try to use the API Explorer: publisher I get a projectNotLinked error.

Best Regards

GuanacoDevs avatar Dec 13 '18 04:12 GuanacoDevs

+1

thebylito avatar Dec 17 '18 00:12 thebylito

The issue is apparently solved. I did Unlink my Play Developer Account from Google Developers Console and created a new service account. However the fix wasn't instant, I actually thought that didn't work, but now it is working again.

GuanacoDevs avatar Dec 17 '18 00:12 GuanacoDevs