Jump to content


Welcome! You're currently a Guest.

If you'd like to join in the Discussion, or access additional features in our forums, please sign in with your Evernote Account here. Have an Evernote Account but forgot your password? Reset it! Don't have an account yet? Create One! You'll need to set your Display Name before your first post.

HTTP API (Auth and retrieving images)


  • Please log in to reply
7 replies to this topic

#1 lhbs

lhbs

  • Pip
  • Title: Member
  • Group: Members
  • 9 posts

Posted 01 February 2012 - 10:03 AM

Hi,

I really have problems using the http api. It worked well doing a ressource request in the sandbox environment. I now switched to production. I changed the url of course. So I do this:

$("#images").append('<img src="https://www.evernote.com/shard/s1/res/' + GUID + '" />');

As a response I get a page not found. Do I still have to do auth? can I do this via <img src="...&auth=token" /> What shardId I have to use?

I really would appreciate it if you can help me out here. thanx.

best,
claus

#2 Julien Boedec

Julien Boedec

  • Title: Bushwhacker
  • Group: Evernote Employee
  • 121 posts

Posted 01 February 2012 - 05:23 PM

The shardId is static in your URL (set to s1) which is causing the issue in this case. That example works fine on sandbox because there is only one shard, but we have over on hundred on the production service. When you authenticate the user on the service, you also receive the shardId. Use it to construct the URL.

#3 lhbs

lhbs

  • Pip
  • Title: Member
  • Group: Members
  • 9 posts

Posted 02 February 2012 - 10:07 AM

View PostJulien Boedec, on 01 February 2012 - 05:23 PM, said:

The shardId is static in your URL (set to s1) which is causing the issue in this case. That example works fine on sandbox because there is only one shard, but we have over on hundred on the production service. When you authenticate the user on the service, you also receive the shardId. Use it to construct the URL.

cool thanx. i got the shardId now, but I still have to do auth. I tried it with ?auth=token ... but it's not working. can you pls drop me another line on that :)

#4 lhbs

lhbs

  • Pip
  • Title: Member
  • Group: Members
  • 9 posts

Posted 02 February 2012 - 11:51 AM

I got it. I didn't change anything, it suddenly worked. thanx anyway for the shardId thingy!

#5 Julien Boedec

Julien Boedec

  • Title: Bushwhacker
  • Group: Evernote Employee
  • 121 posts

Posted 02 February 2012 - 06:55 PM

It worked because the user is on shard 1. The problem will be back very quickly if you don't make the shardId dynamic.

#6 lhbs

lhbs

  • Pip
  • Title: Member
  • Group: Members
  • 9 posts

Posted 03 February 2012 - 02:54 PM

View PostJulien Boedec, on 02 February 2012 - 06:55 PM, said:

It worked because the user is on shard 1. The problem will be back very quickly it you don't make the shardId dynamic.

Hi again. Regarding the shardId, I made it dynamic and it works fine. However, as you've forseen, it doesn't show my pictures anymore. The funny thing is: when I read out the url (e.g. with alert) and put it into my browser window, the image will be shown.

but when I write the SAME url into my src attribute, I do not get the image. How can this be?

$("#images").append('<img src="https://www.evernote.com/shard/' + shardId + '/res/' + imageUrls[imageCnt] + '?auth=' + token + '" />');

If you have an idea about this, pls let me know. Thanx you very much!

#7 occulens

occulens

  • Pip
  • Title: Member
  • Group: Members
  • 7 posts

Posted 04 February 2012 - 06:53 PM

Hi,

I am also trying to use the HTTP API for images. I am working on a project that uses public notebooks only. I can construct URLs to access images, such as this one:

http://evernote.com/...864506d7a7.jpeg

If you click on the link, you will see that the image loads fine. However, when I try to imbed this as an <img> tag on my page (which is running from a localhost:8080 google app engine dev server), I get an error 403 Forbidden. Here is what I see from firebug in regards to that request:

Response Headers
HTTP/1.1 403 Forbidden
Content-Type: text/html
Content-Length: 3069
Date: Sat, 04 Feb 2012 18:39:33 GMT
Server: Evernote/1.0


Request Headers
GET /shard/s39/res/f29232aa-5207-4f94-89e3-b77d4de7810f.bmp HTTP/1.1
Host: evernote.com
User-Agent: Mozilla/5.0 (Ubuntu; X11; Linux x86_64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
Referer: http://localhost:808...3b-2d02cf309d26
Cookie: __utma=195394419.1404069355.1328380146.1328380146.1328380146.1; __utmz=195394419.1328380146.1.1.utmcsr=linkpad.me|utmccn=(referral)|utmcmd=referral|utmcct=/eric; member_id=61435; itemMarking_forums=eJxLtDK0qi62MrNSSi9KLU4tUbJOBIlkWpkYWGdaGRobmZsZmJgZm1rX1gJcMBgcDEg%2C; itemMarking_forums_items=eJxVz8kVwyAMBNCWmBHacDU5poa89B4s7Gdy1EfL8Bqw8XkPimkc7wFhgNb7WTCsL_NIEdoswjI3g8xcIgHsVoWn8kFmYXheV9w1zM-NpCY3XFw5oLZ1qvgajz_Uwmh9x147m2PHiinwx6BrmvV2o6CmQ3LDVjHRqRfO4JGtOqH3ceP8HY_vD04-TlA%2C; _jsuid=3238691342; pass_hash=d696d5d690ec639a7cf87e6f796efb16; __utmc=195394419; __utmb=195394419.3.10.1328380146
If-None-Match: "3724"
Cache-Control: max-age=0




If you copy paste the following code into a test.html file, you'll see that it works too.

<html>
<head>
</head>
<body>
<img src=http://evernote.com/shard/s39/res/f29232aa-5207-4f94-89e3-b77d4de7810f.bmp" />
<img src=http://evernote.com/shard/s39/res/122ea655-d656-49bc-a055-11b9343486a5.bmp" />
<img src=http://evernote.com/shard/s39/res/3cc91eba-7332-44e8-9ddc-95864506d7a7.jpeg" />
</body>
</html>



There must be something different about my request when using the localhost server? Any advice on what may be causing the 403 Forbidden?

#8 occulens

occulens

  • Pip
  • Title: Member
  • Group: Members
  • 7 posts

Posted 04 February 2012 - 07:51 PM

I think I may have discovered why:

source: http://discussion.ev...h__1#entry58994

Quote

Just to clarify:
So you are retrieving the ENML from Evernote and then serving an HTML web page from your site that includes <img /> tags with 'src' that points to http://sandbox.evern...shard/s1/res/... ?
So your server is not retrieving the images, but you are telling the browser to get them directly from Evernote?

The server is currently configured to check the "Referrer" header when a browser asks for any Resource and to refuse the request if the Referrer is a different domain. This is added to prevent people from putting images in Evernote and then using us for <img /> tags on other random sites. I.e. we're trying to prevent Evernote from being used as a free "image hosting" service for random web sites.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users

Clip to Evernote