How do I get my estimated earnings from my Google AdMob account to my nodeJS application?

102 Views Asked by At

I've been trying to get my estimated earnings from my Google AdMob account to my nodeJS application. I'm using the googleapis module to get the estimated earnings.

import { google } from "googleapis";
const auth = new google.auth.GoogleAuth({
    keyFile: credsFilePath, // Path to your service account credentials JSON file
    scopes: ["https://www.googleapis.com/auth/admob.readonly"],
  });


  const client = await auth.getClient();
  const admob = google.admob({
    version: "v1",
    auth: client,
  });


  const response = await admob.accounts.mediationReport.generate({
    parent: "accounts/pub-XXXXXXXXXXXXXXX", //Adding my publisher id here
    requestBody: {
      reportSpec : {
        dateRange: {
          startDate: {
            year: 2023,
            month: 1,
            day: 1
          },
          endDate: {
            year: 2023,
            day: 31,
            month: 7
          }
        },
        dimensions: [
          "DATE"
        ],
        metrics: [
          "ESTIMATED_EARNINGS"
        ]
      }
    }

  });

But I'm getting the error 401 Unauthorized so I'm assuming my service account doesn't have the permission to access my AdMob account. Now in the cloud console, I'm trying to add a role to this service account which will give it access to AdMob (I'm assuming thats what I gotta do here cause thats what some research online says, I could be wrong), but I don't see any AdMob related roles in the list.

Any idea where should I go from here?

0

There are 0 best solutions below