Posts tagged with google-api

Hope you are safe and good for this pandemic time. I am developing some functional to fetch data from google ads using google-ads-node. But for now I met one issue.

Error: 3 INVALID_ARGUMENT: Invalid customer ID '... .... ...'. 

However it is set correctly on ads account. Please understand me messy picture. The code I used like this.

const auth = await authenticateGoogle(`keys/${process.env.GOOGLE_YT3_API_CREDENTIAL_PATH}`, 'installed');   const client = new GoogleAdsClient({     access_token: auth.credentials.access_token,     developer_token: process.env.DEV_TOKEN,     parseResults: true,   });   const service = client.getService("GoogleAdsService", { useStreaming: true });   const request = new SearchGoogleAdsStreamRequest();   request.setQuery(`     SELECT       campaign.resource_name,       metrics.impressions,       segments.date     FROM        campaign     WHERE        segments.date BETWEEN "2019-01-01" AND "2020-01-01"   `);   request.setCustomerId(process.env.CUSTOMER_ID);   const call = service.searchStream(request);     const chunks = [];     call.on("error", err => reject(err));     call.on("data", (chunk) => chunks.push(chunk));     call.on("end", () => resolve(chunks)); 

Would you help me how I can figure out this issue please? Thank you.

Note - Below all these points I am doing manually, I want to make it automatically with programming.

I have several questions regarding "google-cloud-iam"

Are these below points are possible programmatically via "google-cloud-iam" any type of API?

  1. Do Link Google Adwords account with Google analytics (User is using the same Gmail account for AdWords and Analytics account)
  2. Create a project in the cloud google console, enable "Analytics API", create a service account, and download the P12 Key at the server-side or client-side.
  3. Add Service account id in Google Analytics user management

I'm trying to pull a report from the Google Ads API into Google sheets and I can't get the API to recognize my query as a query

Here's the code and error I'm getting:

    function basicReport() {   var query = {     "query" : "SELECT campaign.name, campaign.status FROM campaign ORDER BY campaign.id"   };      var body = JSON.stringify(query);      var head = {     'Developer-token' : "<Dev token>",     'login-customer-id' : <Manager ID>,     'Authorization' : "Bearer <Auth token>",   }; var options = {   'method' : 'POST',   'content-type': 'application/json',   'headers' : head,   'payload' : body,   'muteHttpExceptions' : true };    var response = UrlFetchApp.fetch('https://googleads.googleapis.com/v4/customers/<Customer ID>/googleAds:searchStream', options);   var json = response.getContentText();   var data = JSON.parse(json); 

But I constantly get the error:

"error": {     "code": 400,     "message": "Invalid JSON payload received. Unknown name \"{\"query\":\"SELECT campaign.name, campaign.status FROM campaign ORDER BY campaign.id\"}\": Cannot bind query parameter. Field '{\"query\":\"SELECT campaign' could not be found in request message.",     "status": "INVALID_ARGUMENT",     "details": [       {         "@type": "type.googleapis.com/google.rpc.BadRequest",         "fieldViolations": [           {             "description": "Invalid JSON payload received. Unknown name \"{\"query\":\"SELECT campaign.name, campaign.status FROM campaign ORDER BY campaign.id\"}\": Cannot bind query parameter. Field '{\"query\":\"SELECT campaign' could not be found in request message." 

I've run the query in OAuth playground (https://developers.google.com/oauthplayground) and it worked there, so I know the query is ok.

I've tried passing the body as an object not a string, but then I get a 500 error.

I want to propose a budget for an ads account under my manager account. I have the following YAML file:

developer_token: 13245 login-customer-id: 1324567891 customer-id: 1324567891 user_agent:  13245 client_id: 13245 client_secret: 13245 refresh_token: 13245 

When i try to run my script, i get this error:

Error with message

"User doesn't have permission to access customer. Note: If you're accessing a client customer, the manager's customer id must be set in the 'login-customer-id' header.

This is the code that i use, from the example python library:

    try:     account_budget_proposal_response = (       account_budget_proposal_service.mutate_account_budget_proposal(           customer_id, account_budget_proposal_operation)) 

I'm trying to modularize a type of report from the API. This is my query for the request:

content = ['CampaignId', 'AdvertisingChannelType', ...] report_query = (adwords.ReportQueryBuilder()                        .Select(content)                        .From('CAMPAIGN_PERFORMANCE_REPORT')                        .During(start_date=since,end_date=until)                        .Build()) 

However, I'm having a problem with the .Select() statement since its common usage is .Select('CampaignId', 'AdvertisingChannelType', ...) (as the list but without the brackets []) and in my query I'm parsing the arguments as a list, which of course returns an error.

My question is, how can I parse the elements of content as required? I've tried turning the list into a string but it doesn't work as all the list becomes a single element. I can't assign by hand the elements since it's number may vary (will be used for more than one client).

Any help will be appreciated. Thanks!