Skip to content

Instantly share code, notes, and snippets.

@rveitch
Created July 2, 2021 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rveitch/4c129d09b92c70e74156a7eccdf243d7 to your computer and use it in GitHub Desktop.
Save rveitch/4c129d09b92c70e74156a7eccdf243d7 to your computer and use it in GitHub Desktop.
Google-Ads-Api example
/* eslint-disable no-debugger, no-console */
process.env.GRPC_VERBOSITY = 'DEBUG';
process.env.GRPC_TRACE = 'all';
const {
GoogleAdsApi,
services: { KeywordSeed },
} = require('google-ads-api'); // package v5.2.0 = Google Ads API to v7
const Env = require('../../config/env.js');
const Config = require('../../config/index.js');
/* *** Config *** */
const PAGE_SIZE = 10;
const KEYWORDS = ['content marketing'];
/* EXAMPLE: Google Ads API v7 - Generate Keyword Ideas */
(async () => {
await Env.loadEnv();
const client = new GoogleAdsApi({
client_id: Config.get('GOOGLE_ADS_CLIENT_ID'),
client_secret: Config.get('GOOGLE_ADS_CLIENT_SECRET'),
developer_token: Config.get('GOOGLE_ADS_DEVELOPER_TOKEN'),
});
const customer = client.Customer({
customer_id: Config.get('GOOGLE_ADS_CUSTOMER_ACCOUNT_ID'),
refresh_token: Config.get('GOOGLE_ADS_REFRESH_TOKEN'),
});
const keywordSeed = new KeywordSeed({ keywords: KEYWORDS });
const generateKeywordIdeaResponse = await customer.keywordPlanIdeas.generateKeywordIdeas({
customer_id: customer.credentials.customer_id,
page_size: PAGE_SIZE,
keyword_seed: keywordSeed,
}).catch((e) => console.error(e));
console.log(JSON.stringify(generateKeywordIdeaResponse, null, 2));
debugger;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment