API объявлений локальных служб Google

#google-api #google-api-php-client #google-api-nodejs-client

#google-api #google-api-php-client #google-api-nodejs-client

Вопрос:

Я пытаюсь использовать Node Google Local Services API, который еще не задокументирован в Google, поэтому не уверен, работает он или еще нет. Обратите внимание, что я также использовал PHP API, и я получил те же результаты, поэтому не думайте, что это связано с языком. Я предполагаю, что это работает из-за этого потока.

Это код, который я использую:

 const {google} = require('googleapis');
const localservices = google.localservices('v1');

async function main() {
  //https://developers.google.com/identity/protocols/oauth2/scopes
  const auth = new google.auth.GoogleAuth({
    // Scopes can be specified either as an array
    // keyFile: './auth.json',
    // Took scopes from error:
    // 'www-authenticate': 'Bearer realm="https://accounts.google.com/", error="insufficient_scope", scope="https://www.googleapis.com/auth/adwords https://adwords.google.com/api/adwords https://adwords.google.com/api/adwords/ https://adwords.google.com/api/adwords/cm"',
    scopes: [
      'https://www.googleapis.com/auth/adwords',
      'https://adwords.google.com/api/adwords',
      'https://adwords.google.com/api/adwords/',
      'https://adwords.google.com/api/adwords/cm'
    ],
  });
  // Acquire an auth client, and bind it to all future calls
  const authClient = await auth.getClient();
  google.options({auth: authClient});

  // Do the magic
  const res = await localservices.detailedLeadReports.search({
    // Day of month. Must be from 1 to 31 and valid for the year and month, or 0 if specifying a year by itself or a year and month where the day is not significant.
    'endDate.day': 23,
    // Month of year. Must be from 1 to 12, or 0 if specifying a year without a month and day.
    'endDate.month': 9,
    // Year of date. Must be from 1 to 9999, or 0 if specifying a date without a year.
    'endDate.year': 2020,
    // The maximum number of accounts to return. If the page size is unset, page size will default to 1000. Maximum page_size is 10000. Optional.
    pageSize: 1000,
    // The `next_page_token` value returned from a previous request to SearchDetailedLeadReports that indicates where listing should continue. Optional.
    // pageToken: 'placeholder-value',
    // A query string for searching for account reports. Caller must provide a customer id of their MCC account with an associated Gaia Mint that allows read permission on their linked accounts. Search expressions are case insensitive. 
    // Example query: | Query | Description | |-------------------------|-----------------------------------------------| | manager_customer_id:123 | Get Detailed Lead Report for Manager with id | | | 123. | Required.
    query: "| Query | Description | |-------------------------|-----------------------------------------------| |manager_customer_id:111-222-3333 | Get Account Report for Manager with id 111-222-3333. |",
    // Day of month. Must be from 1 to 31 and valid for the year and month, or 0 if specifying a year by itself or a year and month where the day is not significant.
    'startDate.day': 1,
    // Month of year. Must be from 1 to 12, or 0 if specifying a year without a month and day.
    'startDate.month': 1,
    // Year of date. Must be from 1 to 9999, or 0 if specifying a date without a year.
    'startDate.year': 2020
  });
}
  

И я получаю эту ошибку:

   {
    ...
    code: 400,
    errors: [
      {
        message: 'Request contains an invalid argument.',
        domain: 'global',
        reason: 'badRequest'
      }
    ]
  }
  

Я получил идентификатор клиента, используя эту логику.

Комментарии:

1. вы пробовали query: "|manager_customer_id:111-222-3333 | Get Account Report for Manager with id 111-222-3333. |", ?

2. Я сделал: ( Не повезло. Также пробовал с другим запросом: подробный отчет о лидах и так далее, не повезло: (

3. Странно, что он не работает, также не работает справочная страница API, я видел созданную вами ошибку, надеюсь, кто-нибудь ответит на ошибку

4. Да, справочной страницы API нет. Я полагаю, что, возможно, API не работает, или я не уверен, что я ошибся.

Ответ №1:

Это суть с полным кодом, который заставляет его работать.

Во-первых, области должны выглядеть следующим образом:

   const url = oauth2Client.generateAuthUrl({
    // 'online' (default) or 'offline' (gets refresh_token)
    access_type: 'offline',
    // If you only need one scope you can pass it as a string
    // https://developers.google.com/identity/protocols/oauth2/scopes
    scope: ['https://www.googleapis.com/auth/adwords'],
  })
  

Затем запрос будет:

 query: 'manager_customer_id:XXXX'
  

Где XXX — числовой номер идентификатора клиента менеджера для учетной записи MCC (без каких-либо тире). Смотрите Логику, чтобы получить ее здесь.

Подробные отчеты customer_id также могут предоставляться или не предоставляться:

 query: 'manager_customer_id:XXXX;customer_id:YYYY'
  

Комментарии:

1. Удаление тире — это то, что меня сбило с толку!