这是我正在使用的代码: const {google} = require('googleapis');const localservices = google.localservices('v1');异步函数main(){//https://developers.google.com/identity/protocols/oauth2/scopesconst auth = new google.auth.GoogleAuth({//范围可以指定为数组//keyFile:'./auth.json',//从错误中获取作用域://'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"',范围:["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'],});//获取身份验证客户端,并将其绑定到以后的所有调用const authClient =等待auth.getClient();google.options({auth:authClient});//做魔术const res =等待localservices.detailedLeadReports.search({//每月的一天.必须为1到31,并且对年和月有效;如果单独指定年或不重要的年和月,则必须为0."endDate.day":23,//一年中的月份.必须为1到12,如果指定没有月份和日期的年份,则必须为0."endDate.month":9//日期年份.必须为1到9999,如果指定不带年份的日期,则必须为0.'endDate.year':2020年,//要返回的最大帐户数.如果未设置页面大小,则页面大小将默认为1000.最大page_size为10000.可选.pageSize:1000,//从上一个请求返回到SearchDetailedLeadReports的`next_page_token`值,该值指示应继续列出的位置.可选的.//pageToken:占位符值",//用于搜索帐户报告的查询字符串.呼叫者必须提供其MCC帐户的客户ID和关联的Gaia Mint,以允许对其关联帐户进行读取权限.搜索表达式不区分大小写.//示例查询:|查询|描述| ------------------------- | ----------------------------------------------- ||manager_customer_id:123 |获取具有ID的经理的详细潜在客户报告|||123.必需的.查询:查询|描述| ------------------------- | ----------------------------------------------- || manager_customer_id:111-222-3333 |获取ID为111-222-3333的经理帐户报告.|",//每月的一天.必须为1到31,并且对年和月有效;如果单独指定年或不重要的年和月,则必须为0.'startDate.day':1//一年中的月份.必须为1到12,如果指定没有月份和日期的年份,则必须为0.'startDate.month':1//日期年份.必须为1到9999,如果指定不带年份的日期,则必须为0.'startDate.year':2020});} 我收到此错误: {...代码:400,错误:[{消息:请求包含无效的参数.",域:全局",原因:"badRequest"}]} 我使用此逻辑获得了客户ID.解决方案这是要点包含使之正常工作的完整代码.首先,范围应如下所示: const url = oauth2Client.generateAuthUrl({//'online'(默认)或'offline'(获取refresh_token)access_type:离线",//如果只需要一个作用域,则可以将其作为字符串传递//https://developers.google.com/identity/protocols/oauth2/scopes范围:['https://www.googleapis.com/auth/adwords'],}) 然后,查询将是: 查询:'manager_customer_id:XXXX' 其中XXX是我的客户中心"帐户的经理客户ID的数字(不带任何破折号).在此处中查看获得它的逻辑.对于详细报告,可能会也可能不会提供 customer_id : 查询:'manager_customer_id:XXXX; customer_id:YYYY' I'm trying to use the Node Google Local Services API, which is not documented yet in Google, so not sure if it's working or not yet. Note I used the PHP API as well, and I got the same results, so do not think it's related to the language. I assume it is working because of this thread.This is the code I'm using: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 });}And I'm getting this error: { ... code: 400, errors: [ { message: 'Request contains an invalid argument.', domain: 'global', reason: 'badRequest' } ] }I got the customer id using this logic. 解决方案 This is a gist with the complete code that makes it work.First, the scopes need to look like this: 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'], })Then, the query will be:query: 'manager_customer_id:XXXX'Where XXX is the numeric number of the manager customer ID for the MCC account (without any dashes). See logic to get it here.For detailed reports, customer_id may or may not be provided as well:query: 'manager_customer_id:XXXX;customer_id:YYYY' 这篇关于Google Local Services Ads API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!