Google API POST调用时出现400分析器错误 [英] 400 Parser error with Google API POST call
问题描述
我试图对Search Console API进行POST调用。我在API Explorer中运行了我的示例,但是当我尝试从流星项目中进行相同的调用时,出现错误: Object {error:Object} error:Object code:400 errors:Array [1]
message:Parse Error
我的代码:
function fetchSEOForWebsite(website){
var call ='webmasters / v3 /网站/'+'mdbootstrap.com'+'/ searchAnalytics / query'
var params = {
searchType:web,
dimensions:[
查询,
date,
page
],
startDate:2016-02-06,
endDate:2016 -02-08
GoogleApi.post(call,{
params:params
},function(error,answer){
console.log(答案);
});
}
在Chrome控制台中,我可以看到POST有效负载:
searchType = web& dimensions = query%2Cdate%2Cpage& startDate = 2016-02-06& endDate = 2016-02-08
相同的查询可以在API Explorer中正常工作:
POST https://www.googleapis.com/webmasters/v3/sites/http%3A%2F%2Fmdbootstrap.com/searchAnalytics/query?key={YOUR_API_KEY}
{
searchType :web,
dimensions:[
query,
date,
page
],
startDate :2016-02-06,
endDate:2016-02-08
}
我做错了什么?
我使用Meteor Google Api
https://github.com/percolatestudio/meteor-google-api
更新:
我也检查了通过API Explorer发送的paylod这是不同的:
{searchType:web,dimensions:[query,date,page
],startDate:2016-02-06,endDate:2016-02-08}
所以它看起来像是由于某些原因,我的参数不作为JSON对象传递...
From percolate:google-api package自述
GoogleApi是一个围绕HTTP的Google OAuth认证包装,因此它
需要相同的论点。例如,要在
GoogleApi.post中传递JSON正文,请使用:
GoogleApi.post('/ your / api / path',{data: jsonBody});
所以我会试着用 data:
来代替 params:
I am trying to make POST call towards Search Console API. I got my example running under API Explorer, however when I try to make the same call from my meteor project, I am getting error:
Object {error: Object} error: Object code: 400 errors: Array[1] message: "Parse Error"
My code:
function fetchSEOForWebsite(website) {
var call = 'webmasters/v3/sites/' + 'mdbootstrap.com' + '/searchAnalytics/query'
var params = {
"searchType": "web",
"dimensions": [
"query",
"date",
"page"
],
"startDate": "2016-02-06",
"endDate": "2016-02-08"
}
GoogleApi.post(call, {
params: params
}, function(error, answer) {
console.log(answer);
});
}
From Chrome console I can see POST payload:
searchType=web&dimensions=query%2Cdate%2Cpage&startDate=2016-02-06&endDate=2016-02-08
The same query works perfectly fine from API Explorer :
POST https://www.googleapis.com/webmasters/v3/sites/http%3A%2F%2Fmdbootstrap.com/searchAnalytics/query?key={YOUR_API_KEY}
{
"searchType": "web",
"dimensions": [
"query",
"date",
"page"
],
"startDate": "2016-02-06",
"endDate": "2016-02-08"
}
What am I doing wrong?
I am using Meteor Google Api https://github.com/percolatestudio/meteor-google-api
UPDATE: I also checked paylod sent via API Explorer and it's different:
{ "searchType": "web", "dimensions": ["query","date","page"
], "startDate": "2016-02-06", "endDate": "2016-02-08" }
So it looks like for some reason my params are not passed as a JSON object to call...
From percolate:google-api package Readme
GoogleApi is a Google OAuth authentication wrapper around HTTP, so it takes the same arguments. For example, to pass a JSON body in GoogleApi.post, use:
GoogleApi.post('/your/api/path', { data: jsonBody });
So I would try with data:
instead of params:
这篇关于Google API POST调用时出现400分析器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!