firebasegoogle-apigoogle-cloud-functionsandroidpublisher

How to get the list of reviews using Google Developer API and Firebase functions?


I need to access to my app reviews, using Google Developer API and Firebase Functions.

My code in Firebase Functions:

const functions = require('firebase-functions')
const admin = require('firebase-admin')
admin.initializeApp(functions.config().firebase);

var {google} = require('googleapis');
const serviceAccount = require('./client_secret.json');
const { JWT } = require('google-auth-library');


const getAuthorizedClient = () => new JWT({
    email: serviceAccount.client_email,
    key: serviceAccount.private_key,
    scopes: ['https://www.googleapis.com/auth/androidpublisher']
});

const getAndroidpublisher = () => google.androidpublisher({
    version: 'v3',
    auth: getAuthorizedClient()
});


const requestProductValidation = () => new Promise((resolve, reject) => {
    getAndroidpublisher().reviews.get({
            packageName: "com.my.packagename"
        }, (err, response) => {

        if (err) {
            console.log(`The API returned an error: ${err}`);
            resolve({status: "Error"});
        } else {

            console.log("ok");

        }
    });
});


exports.hello = functions.https.onRequest((req, res) => {
      return requestProductValidation();
});

I got the error: The API returned an error: Error: Missing required parameters: reviewId.

However I need the list of the reviews not a specific reviews. I suppose this line is wrong getAndroidpublisher().reviews.get but I'm unable to correct it.

What I missed?


Solution

  • I had an error in the request, use reviews.list instead of reviews.get:

    getAndroidpublisher().reviews.list({
              packageName: "com.virgoplay.tchat.weezchat"
          }, (err, response) => {
    
          if (err) {
              console.log(`The API returned an error: ${err}`);
              resolve({status: "Error"});
          } else {
    
              return resolve(response.data.reviews);
          }
     });