【问题标题】:Google Blogger API : Fetch Blog Posts securelyGoogle Blogger API:安全地获取博客文章
【发布时间】:2017-01-26 08:59:12
【问题描述】:

我对 Google API 真的很陌生,所以请耐心等待。我正在尝试从我的博客中获取帖子。博客设置为私人

问题出在这里:

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "ipRefererBlocked",
    "message": "The calling IP address x does not match the IP restrictions configured on the API key. Please use the API Console to update your key restrictions.",
    "extendedHelp": "https://console.developers.google.com/apis/credentials?project=x"
   }
  ],
  "code": 403,
  "message": "The calling IP address x does not match the IP restrictions configured on the API key. Please use the API Console to update your key restrictions."
 }
}

我有一个 Google 帐户,其中有博客、Google API 控制台中的项目和它的 API 密钥。我尝试将 API 密钥限制更改为 HTTP,但出现同样的问题,您的错误消息略有不同。

抓取工作如下:

var apikey = "x";
var blogId = "x";

  $(function(){
    $.ajax({
      type: "GET",
      url:"https://www.googleapis.com/blogger/v3/blogs/"+blogId+"/posts?key="+apikey,
      dataType: "json",
      success: function(data) {
        console.log(data);
      }
    });
  });

我仔细检查了所有变量,它们都是正确的。 API 密钥是正确的,BlogId 也是如此。

用这个炖控制台给我 403 错误。我希望我说得足够清楚。找到答案后我会修复这篇文章:)

【问题讨论】:

    标签: api google-api blogger


    【解决方案1】:

    API 密钥用于访问公共数据。公共数据是不属于用户个人所有的数据。例如,公开上传到 YouTube 的视频。

    您的博主数据是私人用户数据。您将需要使用 Oauth2 来访问它。使用 oauth2 进行身份验证后,您将需要使用 access_token={tokenfrom auth} 而不是使用密钥。

    我不确定为什么 IP 地址不起作用,我之前实际上并没有为此烦恼过。

    【讨论】:

    • 好吧,我不知道!谢谢!
    • 我应该如何进行?我试图弄清楚如何使用 Oauth2.0 访问 Google Blogger API,但我被卡住了。我不知道我应该怎么做。我一直在阅读文档,但对我没有帮助。
    • 我不是 ajax 开发者,所以帮不上什么忙。这可能会帮助您在与人合作后将其更改为使用博客。 developers.google.com/api-client-library/javascript/samples/… javascript 是我能找到的最接近的。一旦你有某种工作在一个新问题下发布你的代码。