使用 Javascript(jQuery) 获取 Google Reader 的未读计数
我正在尝试使用 javascript 获取我的谷歌阅读器的未读计数。
尝试了以下操作:
var unreadURL = "http://www.google.com/reader/api/0/unread-count?all=true";
$.ajax({
url: unreadURL,
success: function (data) {
console.log(data);
}
});
但我收到了 401。我想我必须进行身份验证或其他操作,但我不知道该怎么做。
我发现这个主题,他们首先使用另一个页面进行身份验证,然后设置cookie(如果我读对了这个python),但我不熟悉python,也不知道在javascript中做什么。
有什么提示吗?
i'm trying to get the unread count of my google reader using javascript.
tried the following:
var unreadURL = "http://www.google.com/reader/api/0/unread-count?all=true";
$.ajax({
url: unreadURL,
success: function (data) {
console.log(data);
}
});
but im getting a 401. i think i have to authenticate or something, but i have no idea how to do this.
i found this topic, and they are first authenticating using another page, and then setting a cookie (if i read this python right), but i'm not familiar with python and don't know what to do in javascript.
any hints please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的说法是正确的,您需要进行身份验证才能使用该服务。但是,出于安全原因,现代浏览器不允许客户端代码进行调用到第三方网站。有方法来解决这个问题,但是解决此问题的典型方法是从服务器端向第三方站点发出请求,然后将结果返回给客户端。
因此,在您的情况下,您可以对站点上运行的服务器端代码进行 Ajax 调用。然后,此代码将:
向 Google 进行身份验证
客户端代码(结果可以
也可以是 XML 或 JSON 格式)
You are correct in stating that you need to authenticate to use the service. However, for security reasons modern day browsers do not allow client-side code to make calls to third party sites. There are ways to get around this, but the typical approach to this problem is to make your requests to the third party site form the server-side then return the results to the client.
So, in your case you can make an Ajax call to server-side code running on your site. This code would then:
authenticate to the Google
client-side code (the result could
also be in XML or JSON format)