Facebook API:你如何获得最后创建的图片的网址?

How can I get the url of the picture I just uploaded to facebook through the API?

I need the user to make it its profile picture and I want to give him a fast link to go there.

Alright, so using the Graph API you need to do this:

  • Retrieve a list of of all albums
  • Determine which album was changed most recently
  • Retrieve a list of photos in that album
  • Determine which photo was changed most recently

Here's how you do it:

First you call: https://graph.facebook.com/me/albums

Which gives you a list a list of all the albums, each album has a key called "updated_time". Loop through all the albums and compare them to see which one is the most recent one.

When you have found the most recent one you take the id of that album and call: https://graph.facebook.com/{ the album id }/photos

This will give you a list of all the photos in that album. Each photo has a key called "created_time". Use that to determine which photo is the most recently created. When you have done that you can just take the value in the key "source" which is an url to the full scale of the picture.

If you want a smaller picture there's a key called "images" which contains a list of 4 different sizes; 590x480, 221x180, 130x105 and 92x75. Each of those items in the list has the "source" key.

You can use FQL to do this very fast by issuing the following query:

SELECT object_id FROM photo WHERE aid IN(SELECT aid FROM album WHERE owner = me() ORDER BY modified DESC LIMIT 1) ORDER BY modified DESC LIMIT 1

This will return just the graph object id, which you can then simply issue a graph API request to https://graph.facebook.com/object_id

If you want more fields than just the object_id, check these docs: http://developers.facebook.com/docs/reference/fql/photo/