views:

51

answers:

1

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?

+1  A: 

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:

  • Use the Google ClientLogin API to authenticate to the Google
  • Get the unread-count
  • Return the results to your client-side code (the result could also be in XML or JSON format)
Garett
poorly i can not, because i wanted to do this in an addon for safari. thanks for this information.
choise