Error getting access token: at Object.run (file:///tmp/__pdg__/dist/code/ebf60822dc1bb78a5ee0682fc43453bd038e171d915a4c4c1110d298514af857/component.mjs:53:40)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at null.executeComponent (/var/task/launch_worker.js:229:22)
at MessagePort.messageHandler (/var/task/launch_worker.js:726:28)
**import** { axios } **from** "@pipedream/platform";
**import** { GoogleAdsApi, enums } **from** 'google-ads-api';
export
**default** defineComponent({
props: {
clientId: {
type: “string”,
label: “Client ID”,
},
clientSecret: {
type: “string”,
label: “Client Secret”,
},
refreshToken: {
type: “string”,
label: “Refresh Token”,
},
developerToken: {
type: “string”,
label: “Developer Token”,
},
customerId: {
type: “string”,
label: “Customer ID”,
},
languageId: {
type: “string”,
label: “Language ID”,
},
keywordTexts: {
type: “string[]”,
label: “Keyword Texts”,
},
pageUrl: {
type: “string”,
label: “Page URL”,
},
},
**async** run({ $ }) {
**let** accessToken;
`**try** {`
`**const** tokenResponse = **await** axios($, {`
method: "POST",
url: "https://oauth2.googleapis.com/token",
data: {
client_id: `**this**.clientId,`
client_secret: `**this**.clientSecret,`
refresh_token: `**this**.refreshToken,`
grant_type: "refresh_token",
},
});
accessToken = tokenResponse.data.access_token;
} `**catch** (error) {`
console.error("Error getting access token: ", error);
`**return**;`
}
`**if** (!accessToken) {`
console.error("Failed to obtain access token.");
`**return**;`
}
`**const** client = **new** GoogleAdsApi({`
client_id: `**this**.clientId,`
client_secret: `**this**.clientSecret,`
developer_token: `**this**.developerToken,`
access_token: accessToken,
});
`**const** service = client.getService('KeywordPlanIdeaService');`
`**const** request = {`
customer_id: `**this**.customerId,`
language: `**this**.languageId,`
include_adult_keywords: `**false**,`
keyword_plan_network: enums.KeywordPlanNetwork.GOOGLE_SEARCH_AND_PARTNERS,
};
`**if** (**this**.keywordTexts && !**this**.pageUrl) {`
request.keyword_seed = {
keywords: `**this**.keywordTexts,`
};
}
`**if** (!**this**.keywordTexts && **this**.pageUrl) {`
request.url_seed = {
url: `**this**.pageUrl,`
};
}
`**if** (**this**.keywordTexts && **this**.pageUrl) {`
request.keyword_and_url_seed = {
url: `**this**.pageUrl,`
keywords: `**this**.keywordTexts,`
};
}
`**const** response = **await** service.generateKeywordIdeas(request);`
response.forEach((idea) => {
`**const** competition = idea.keyword_idea_metrics.competition;`
`**const** avgMonthlySearches = idea.keyword_idea_metrics.avg_monthly_searches;`
console.log(`Keyword: ${idea.text}, Competition: ${competition}, Avg Monthly Searches: ${avgMonthlySearches}`);
});
`**return** response;`
},
});