我正在尝试使用 Google Search Console API (nodejs) 来检索查询报告。我们拥有一个配置了我公司所有域的 google 帐户。我们想从 api 中检索完整的域列表,然后从每个域中获取数据。
我们能够正确获取完整的域列表。但是我们可以得到它们的任何数据。
这是代码的一个简短示例。
// auth is the json web token
// domain is the url of the managed domain, example: https://www.asdfg.hif
async function getDomainData(auth, domain){
p = {
auth : auth,
siteUrl : domain,
startDate : '2019-03-01',
endDate : '2019-03-31'
};
try{
portalData = await google.webmasters('v3').searchanalytics.query(p);
console.log( portalData );
return portalData ;
}catch(error){
console.log('Error %s: %s', domain, error);
return null;
}
}//getDomainData
但我总是收到以下错误。这确实是不言自明的。但我无法理解它,因为我在 p 对象中提供了 startDate 和 endDate 参数。我尝试过不同的日期格式,单引号、双引号、无引号……无论我更改什么,我总是收到必填字段错误。
GaxiosError: startDate field is required.
GaxiosError: endDate field is required.
我可以在 Google Search API 控制台中看到错误,所以我认为错误来自服务器,而不是来自我的代码中的某些内容。
从 API Explorer 我可以测试没有错误的 api。
我不知道它会是什么,但它似乎是非常愚蠢的东西。