Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I want to use GOOGLE_APPLICATION_CREDENTIALS json file #5568

Closed
okumar-SDG opened this issue Jul 22, 2024 · 1 comment
Closed

I want to use GOOGLE_APPLICATION_CREDENTIALS json file #5568

okumar-SDG opened this issue Jul 22, 2024 · 1 comment

Comments

@okumar-SDG
Copy link

Hi team,
instead of using export GOOGLE_APPLICATION_CREDENTIALS="/home/ec2-user/Projects/credentials.json"

I want something like const GOOGLE_APPLICATION_CREDENTIALS="/home/ec2-user/Projects/credentials.json" in this code , can anyone help

`// Imports the Google Analytics Data API client library.
const {BetaAnalyticsDataClient} = require('@google-analytics/data');

// Using a default constructor instructs the client to use the credentials
// specified in GOOGLE_APPLICATION_CREDENTIALS environment variable.
const analyticsDataClient = new BetaAnalyticsDataClient();

// Runs a simple report.
async function runReport() {
const [response] = await analyticsDataClient.runReport({
property: properties/${propertyId},
dateRanges: [
{
startDate: '2020-03-31',
endDate: 'today',
},
],
dimensions: [
{
name: 'city',
},
],
metrics: [
{
name: 'activeUsers',
},
],
});

console.log('Report result:');
response.rows.forEach(row => {
console.log(row.dimensionValues[0], row.metricValues[0]);
});
}
`

@sofisl
Copy link
Contributor

sofisl commented Jul 22, 2024

@okumar-SDG, you can add a keyfile property to the constructor:

const analyticsDataClient = new BetaAnalyticsDataClient({keyfileName: 'path-to-your-keyfile'});

see: https://github.com/googleapis/google-auth-library-nodejs/blob/0b78d91534d97b37859a2303b332f8ccd52dbf69/src/auth/googleauth.ts#L91-L99

@sofisl sofisl closed this as completed Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants