Posts tagged with google-ads-api

When I am trying to use webpack in order to build my project and use it on AWS Lambda, I am getting a lot of warnings related to Critical dependency of ./node_modules/grpc. This issue happening once I import {GoogleAdsApi} from 'google-ads-api'; As I can understand this is related to dynamic importing, I might be wrong. As a result, the bundled file is huge (above 4MB) and when zipping it and using it on the Lambda I am getting the following error when the Lambda is triggered: "package.json does not exist at /package.json"

*Typescript
*Node ver 12.x

index.ts

import {GoogleAdsApi} from 'google-ads-api'; export const handler = async (event: any): Promise<any> => {   try {     console.log('Start', event);     // @ts-ignore     const api = new GoogleAdsApi({client_id: 'id', client_secret: 'secret', developer_token: 'dToken'});     return 'success';   } catch (e) {     console.log('Error', e);     throw e;   } }; 
Error: package.json does not exist at /package.json, at Object.exports.find (/var/task/webpack:/node_modules/node-pre-gyp/lib/pre-binding.js:18:1), at Object.<anonymous> (/var/task/webpack:/node_modules/grpc/src/grpc_extension.js:29:1), at Object.<anonymous> (/var/task/index.js:40079:30), at __webpack_require__ (/var/task/webpack:/webpack/bootstrap:19:1), at Object.<anonymous> (/var/task/webpack:/node_modules/grpc/src/client_interceptors.js:144:12), at __webpack_require__ (/var/task/webpack:/webpack/bootstrap:19:1), at Object.<anonymous> (/var/task/webpack:/node_modules/grpc/src/client.js:35:27), at __webpack_require__ (/var/task/webpack:/webpack/bootstrap:19:1), at Object.<anonymous> (/var/task/webpack:/node_modules/grpc/index.js:27:14), at Object.<anonymous> (/var/task/index.js:2460:30) 

Webpack Warnings Webpack Warnings:

WARNING in ./node_modules/bytebuffer/dist/bytebuffer-node.js 29:38-55 Module not found: Error: Can't resolve 'memcpy' in    WARNING in ./node_modules/google-ads-node/node_modules/import-fresh/index.js 28:8-25 Critical dependency: the request of a dependency is an expression WARNING in ./node_modules/grpc/src/grpc_extension.js 32:12-33 Critical dependency: the request of a dependency is an expression WARNING in ./node_modules/node-pre-gyp/lib/pre-binding.js 20:22-48 Critical dependency: the request of a dependency is an expression WARNING in ./node_modules/node-pre-gyp/lib/util/versioning.js 17:20-67 Critical dependency: the request of a dependency is an expression 

webpack.config.js:

`const path = require("path") const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin") module.exports = { mode: "production", entry: "./src/index.ts", resolve: { extensions: [".js", ".jsx", ".json", ".ts", ".tsx"], }, output: { libraryTarget: "commonjs", path: path.join(__dirname, "dist"), filename: "index.js", }, target: "node", module: { rules: [ { // Include ts, tsx, js, and jsx files. test: /.(ts|js)x?$/, exclude: /node_modules/, use: [ { loader: "cache-loader", options: { cacheDirectory: path.resolve(".webpackCache"), }, }, "babel-loader", ], }, ], }, plugins: [new ForkTsCheckerWebpackPlugin()], }` 

I use the Google AdWords API to collect information about the search volume for a specific keyword. But the data I get as a response doesn't match with the data from the keyword planner or other keyword tools. Here I check the search volume for the keyword "Hunde" in Berlin, Germany in german.

targeting_service = adwordsClient.GetService('TargetingIdeaService') selector = {'ideaType': 'KEYWORD', 'requestType' : 'STATS'} selector['requestedAttributeTypes'] = ['KEYWORD_TEXT', 'SEARCH_VOLUME', 'TARGETED_MONTHLY_SEARCHES'] offset = 0 selector['paging'] = {'startIndex' : str(offset), 'numberResults' : str(1)} selector['searchParameters'] = [{    'xsi_type': 'RelatedToQuerySearchParameter',    'queries': ["hunde"] }] selector['searchParameters'].append({    'xsi_type': 'LocationSearchParameter',    'locations': [{'id': '1003854'}] }) selector['searchParameters'].append({    'xsi_type': 'LanguageSearchParameter',    'languages': [{'id': '1001'}] }) page = targeting_service.get(selector) print(page) 

As a response I get:

{     'totalNumEntries': 1,     'entries': [         {             'data': [                 {                     'key': 'KEYWORD_TEXT',                     'value': {                         'Attribute.Type': 'StringAttribute',                         'value': 'hunde'                     }                 },                 {                     'key': 'TARGETED_MONTHLY_SEARCHES',                     'value': {                         'Attribute.Type': 'MonthlySearchVolumeAttribute',                         'value': [                             {                                 'year': 2020,                                 'month': 12,                                 'count': 4743382                             },                             {                                 'year': 2020,                                 'month': 11,                                 'count': 455583                             },                             {                                 'year': 2020,                                 'month': 10,                                 'count': 8797951                             },                             {                                 'year': 2020,                                 'month': 9,                                 'count': 5218694                             },                             {                                 'year': 2020,                                 'month': 8,                                 'count': 5089585                             },                             {                                 'year': 2020,                                 'month': 7,                                 'count': 3149591                             },                             {                                 'year': 2020,                                 'month': 6,                                 'count': 3020638                             },                             {                                 'year': 2020,                                 'month': 5,                                 'count': 4928527                             },                             {                                 'year': 2020,                                 'month': 4,                                 'count': 754959                             },                             {                                 'year': 2020,                                 'month': 3,                                 'count': 5649676                             },                             {                                 'year': 2020,                                 'month': 2,                                 'count': 1590789                             },                             {                                 'year': 2020,                                 'month': 1,                                 'count': 2506674                             }                         ]                     }                 },                 {                     'key': 'SEARCH_VOLUME',                     'value': {                         'Attribute.Type': 'LongAttribute',                         'value': 3825504                     }                 }             ]         }     ] } 

But this data doesn't match with the data from the keyword planer.
Avg. monthly searches (Keyword planner): 10K – 100K

Does somebody knows why the data I'm receiving is wrong?

I have this following code to fetch all list of ads clients comes under a Ads manager account, I am using manager credentials to get list of clients.

public Customer[] GetAllManagerClientsList(string currentUserEmail, string authorizationCode)     {         string baseURL = _configuration.GetValue<string>("URL:SiteURL");         var currentUser = _userRepository.GetIntegratedAppsDetailByEmail(currentUserEmail);         AdsOAuthProviderForApplications oAuth2Provider = (user.OAuthProvider as AdsOAuthProviderForApplications);         oAuth2Provider.Config.OAuth2RedirectUri = baseURL + "/google-auth-callback";         oAuth2Provider.FetchAccessAndRefreshTokens(authorizationCode);         //Get customerID         user.Config.OAuth2AccessToken = oAuth2Provider.Config.OAuth2AccessToken;         user.Config.OAuth2RefreshToken = oAuth2Provider.Config.OAuth2RefreshToken;         CustomerService customerService = (CustomerService)user.GetService(AdWordsService.v201809.CustomerService);         var customersList = customerService.getCustomers();         var ClientCustomers = customersList != null && customersList.Length > 0 ? customersList.Where(c => c.canManageClients == false).ToList() : null;         if (ClientCustomers.Count() > 0)         {             return ClientCustomers.ToArray();         }         else         {             return null;         }     } 

I use “google-ads-api” to manage google ads. And api needs “customer_account_id” to initialization. However, I Couldn’t found how to get “customer_account_id” programmatically from user.

I used “react-google-login” in front-end, but there is no “customer_account_id” in the response. What is the best way to get customer_account_id?

Im building an app with google ads api using a service account auth flow (server to server).

The problem: the auth part is not working... I keep getting a 401 error.

Sample of the request:

const request = require('request'); .... request({   'method': 'GET',   'url': 'https://googleads.googleapis.com/v6/customers/XXXXXXXX',   'headers': {     'Authorization': 'Bearer XXXXXXXX',     'developer-token': 'XXXXXXXX',     'Content-Type': 'application/json'   } }) ... 

or

curl --location --request GET 'https://googleads.googleapis.com/v6/customers/XXXXXXXX' \ --header 'Authorization: Bearer XXXXXXXX' \ --header 'developer-token: XXXXXXXX' \ --header 'Content-Type: application/json' 

[ERROR] Response from google ads api:

{         "code": 401,         "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",         "status": "UNAUTHENTICATED"     } 

I cant seem to find out why Im getting this authentication error.

What I have tried:

  1. Following this guide step by step -> https://developers.google.com/google-ads/api/docs/oauth/service-accounts
  2. Using the python library -> https://github.com/googleads/googleads-python-lib
  3. Using the google ads API with REST (no library)
  4. On localhost server
  5. On the production server (the www.g-suite.com domain linked to the account)

Whatever method or environment I try, it results in the same error.

Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential 

Steps I have implemented:

  • Created a google ads manager account
  • Generated a valid developer token for that account
  • Created project in Google cloud platform
  • Opened a service account inside the project
  • Created a private key for the service account
  • Granting impersonation abilities in the G Suite domain for this scope: https://www.googleapis.com/auth/adwords
  • Enabled domain-wide delegation on the service account
  • Generated the access token with the key json file.

Generating the access token:

const { google } = require('googleapis'); const getAccessToken = async () => {     const SCOPES = ['https://www.googleapis.com/auth/adwords'];     const authClient = new google.auth.GoogleAuth({         keyFile: './pathtokeyfile.json',         scopes: SCOPES,     });     const token = await authClient.getAccessToken();     return token; }; 

I am surely missing something, but am not sure what it is..

Will be super grateful if someone can share a solution!! thanks champs 👍