Google Reader API - 将全部标记为已读

发布于 2024-10-08 17:16:22 字数 1212 浏览 4 评论 0原文

我正在尝试编写一个脚本,将我的所有提要项目标记为在 Google Reader 中已阅读。它应该像将 4 个变量发布到 API 链接一样简单。但是,我可以成功向 Google 发送 HTTP POST 且不会收到 400 错误的唯一方法是使用简单的 HTML FORM POST,如下所示。我尝试过 PHP cURL,但我收到来自 Google 的 400 错误,指出我发出了错误的客户端请求。

<form method="post" action="http://www.google.com/reader/api/0/mark-all-as-read">
   <input type="hidden" name="s" value="user/10408189040522127442/state/com.google/reading-list" />
   <input type="hidden" name="t" value="Your reading list" />
   <input type="hidden" name="ts" value="<?php echo time(); ?>" />
   <input type="hidden" name="T" value="<?php session_start(); echo $_SESSION['token']; ?>" />                
   <input type="button" value="Mark All As Read" /></form>

使用 HTML 表单(就像我尝试使用 cURL 一样)提交相同的详细信息效果很好,成功地将所有项目标记为已读,但由于 FORM ACTION 设置为外部站点,因此您在提交时会被重定向到该站点。为了解决这个问题,我尝试使用以下内容进行 AJAX 表单提交,因此没有重定向,但这不起作用,也没有提交任何内容。

$(document).ready(function(){
    $("input[type=button]").click(function() {
        $.post($('form').attr("action"), $('form').formSerialize()); 
    });
});

有人可以建议吗? 1) 为什么 cURL POST 不起作用,而简单的 HTML FORM POST 却起作用? 2) 为什么我不能(静默)通过 AJAX 提交来提交 HTML 表单?

I am trying to write a script which marks all my feed items as read within Google Reader. It should be as simple as posting 4 variables to an API link. However, the only way I can successfully make an HTTP POST to Google without getting a 400 error back is a simple HTML FORM POST as follows. I have tried PHP cURL but I get a 400 error from Google stating I have made a bad client request.

<form method="post" action="http://www.google.com/reader/api/0/mark-all-as-read">
   <input type="hidden" name="s" value="user/10408189040522127442/state/com.google/reading-list" />
   <input type="hidden" name="t" value="Your reading list" />
   <input type="hidden" name="ts" value="<?php echo time(); ?>" />
   <input type="hidden" name="T" value="<?php session_start(); echo $_SESSION['token']; ?>" />                
   <input type="button" value="Mark All As Read" /></form>

Submitting the same details using an HTML FORM (as I tried with cURL) works fine, successfully marking all items as read but because the FORM ACTION is set to an external site, you are redirected to it upon submission. To get around this I tried to do an AJAX FORM submission with the following, so there is no redirection but this doesn't work and nothing is submitted.

$(document).ready(function(){
    $("input[type=button]").click(function() {
        $.post($('form').attr("action"), $('form').formSerialize()); 
    });
});

Can anyone advise?
1) Why does a cURL POST not work but a simple HTML FORM POST does?
2) Why can't I (silently) submit the HTML FORM with an AJAX submission?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月光色 2024-10-15 17:16:22

Google 在发布帖子时可能需要设置某些标头,这就是为什么它可能会响应 400 错误。检查使用 cURL 提交时是否也设置了使用基本

发送的相同标头。

另外,您无法 $.post() 到 Google 的原因是由于同源政策。

Google may require certain headers to be set when doing the post, which is why it may be responding with a 400 error. Check that the same headers that are sent using the basic <form> are also set when submitting it using cURL.

Also, the reason why you can't $.post() to Google is due to the same origin policy.

抹茶夏天i‖ 2024-10-15 17:16:22

谷歌确实要求每个帖子都有一个额外的标题,有些帖子也需要额外的标题。

curl_setopt($ch, CURLOPT_HTTPHEADER, array('授权: GoogleLogin auth=' . $auth));

要获得身份验证,您需要点击 https://www.google.com/accounts/ClientLogin

看看这个答案,Google Reader API?

Google does require an additional header for every post and some gets.

curl_setopt ($ch, CURLOPT_HTTPHEADER, array('Authorization: GoogleLogin auth=' . $auth));

to get the auth you need to hit https://www.google.com/accounts/ClientLogin

Take a look at this answer, Google Reader API?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文