1

I am trying to access posterous API , to POST some content to site via google chrome extension ( and otherwise ) .

Since it's a public API , so I expect it to allow everyone to post , but for some reason , it does'nt allow to post .

However everytime I get error .

Same error comes when I access it from browsers

here's the error when accessed via browser

http://localhost is not allowed by Access-Control-Allow-Origin

here's the error when accessed via chrome extension

XMLHttpRequest cannot load http://posterous.com/api/2/users/me/sites/primary/posts?api_token=vxgufysnzlDwmEtkbDbzHtxxBADsEFGr&email=***@gmail.com&password=***. Origin chrome-extension://maabelkjnhafpphacjecmcnkkmjndjgl is not allowed by Access-Control-Allow-Origin.

Here's the code :

$.ajax({
        //type: 'GET',
        url: 'http://posterous.com/api/2/users/me/sites/primary/posts?api_token=vxgufysnzlDwmEtkbDbzHtxxBADsEFGr&email=shahid1376@gmail.com&password=WHY_DID_YOU_PUT_YOUR_REAL_PASS',
      // url:'http://posterous.com/api/2/users/me/sites/primary/posts/public',
       type : 'POST',

        dataType: 'json',
        crossDomain: true,
        data: "{'title': 'test posterous'}",
        contentType:'text/plain',
        success:function result(data) {
                alert("Call completed successfully"); 
        }
mattsven
  • 22,305
  • 11
  • 68
  • 104
user724275
  • 23
  • 1
  • 4

1 Answers1

4

Your manifest.json file should have the two domains you're looking to use in the permissions:

"permissions": [
    "http://*.posterous.com/",
    "http://localhost/"
]

For what it's worth, I wouldn't include localhost in your permissions; rather, use the domain you plan to use in production and then use a hosts line to redirect the domain to your own server. This will let you develop on your own server but won't force your users to allow permissions on localhost which they might not expect.

Jimmy Sawczuk
  • 13,488
  • 7
  • 46
  • 60
  • Exactly. From Google Code: http://code.google.com/chrome/extensions/manifest.html#permissions "Required if the extension wants to interact with the code running on pages. Many extension capabilities, such as cross-origin XMLHttpRequests, programmatically injected content scripts, and the cookies API require host permissions. For details on the syntax, see Match Patterns." – mattsven Apr 28 '11 at 14:53
  • Nexxeus thanks for replacing the original pass , It skipped out of my mind :) – user724275 Apr 28 '11 at 21:05