开发者

Google Reader API - Mark All As Read

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 P开发者_运维问答OST not work but a simple HTML FORM POST does? 2) Why can't I (silently) submit the HTML FORM with an AJAX submission?


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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜