首页 > 解决方案 > 在 Google SearchAnalytics API 中发出 POST 请求时出现 404 错误

问题描述

我正在尝试发出 POST 请求以从 Google SearchAnalytics API 获取 SearchAnalytics 数据。

我正在从网站管理员 API 资源管理器工具中获取数据。但是当我从 Node js 发出相同的请求时,我收到 404 错误。

以下是我尝试过的:

 request.post({
           headers: {
              'content-type' : 'application/json',
              'Authorization' : 'Bearer '+access_token
            },
               url:  siteURL,
               json : {
                   'startDate':'2018-06-01',
                   'endDate':'2018-06-22'
               }
            },
            function(error, response, body)
            {
                  console.log('Error - '+error);
                  console.log('Response - '+JSON.stringify(response));
                  console.log('Body - '+body);
                  res.end();
            });

来自谷歌的回应:

  {"statusCode":404,"body":"Not Found",....}

标签: node.jsgoogle-search-api

解决方案


经过几个小时的挣扎,终于发现问题出在我的siteURL变量上。

以前的网址无效

var siteURL = 'https://example.com'

工作网址

var siteURL = 'https%3A%2F%2Fexample.com'

推荐阅读