Hi everyone i am trying to build an EMM using andoid managemnt api, following their qucik guid and then creating my own project with service account. I got the public / private keys in json file and stored them in my pc , now i am trying to create createAndroidManagementClient and it gives me credintial error, here is a snipit of my code.
const { google } = require('googleapis');
const { auth } = require('google-auth-library');
const fs = require('fs').promises;
const path = require('path');
// Path to your service account JSON key file
const SERVICE_ACCOUNT_KEY_FILE = 'C:\\Users\\User\\Desktop\\happyIconProjects\\MDM github\\AndroidManagmentAPI\\backend\\src\\Google\\keys\\mobile-device-managment-409407-20c331616ec6.json';
// Scopes required for Android Management API
const SCOPES = ['https://www.googleapis.com/auth/androidmanagement'];
async function createAndroidManagementClient() {
// Create credentials using your service account key file
console.log(SERVICE_ACCOUNT_KEY_FILE)
const jsonContent = await fs.readFile(SERVICE_ACCOUNT_KEY_FILE, 'utf8');
const serviceAccount = JSON.parse(jsonContent);
const authClient = await auth.fromJSON(serviceAccount, SCOPES);
console.log("we passed here ")
console.log(serviceAccount)
// Create the API client
const androidmanagement = google.androidmanagement({
version: 'v1',
auth: authClient,
});
return androidmanagement;
}
i checked my service accounts and its roles. the error i get says "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential.