Well, I’m guessing that you came to this page because you are also a developer of some type
. Let me say first off that the Facebook API is way more complex than it needs to be. Ugh, what a mess. Anyways, after getting a couple of headaches trying to understand the documentation, then digging through the API code in order to figure stuff out, I got it all to work. The source code can be viewed in my Sourceforge SVN repository here. Here’s the general steps this application follows:
Step-by-Step Walkthrough
1) If user has not added the application and/or logged into it yet, send them to: http://www.facebook.com/login.php?api_key=your_api_key&v=1.0 2) Once they login to Facebook, they are returned to the application with an auth_token appended to the URL, like this: http://fbpics.meltingice.net/index.php?auth_token=random_characters 3) The application now creates a session with Facebook so that you can retrieve information. It does so using this code: $session = $facebook->do_get_session($_GET['auth_token']); 4) This part got a little tricky and seemed to differ from the documentation in my case, but I then stored the session key and user ID in a session variable by doing this: $_SESSION['session_key'] = $_COOKIE[$appapikey.'_session_key']; $_SESSION['session_uid'] = $_COOKIE[$appapikey.'_user']; 5) Once I have that information stored, I can then call any method I want from Facebook. The one which retrieves all of your tagged photos is: $pics = $facebook->api_client->photos_get($_SESSION['session_uid'],null,null); This took some experimentation, but the Facebook API Test Console really came in handy here. 6) I filter the images by excluding ones you’ve uploaded. I simply do this by doing: if($pic['owner']!=$_SESSION['session_uid']) in the loop that outputs the images. In that same loop, I add the image URLs to a $_SESSION array for use later: $_SESSION['images'][$pic['pid']] = $pic['src_big']; 7) When the user clicks the “Prepare my Download” link, an Ajax call is made that takes all of the image URLs that were stored in the $_SESSION array and downloads them to my server. I do this using the copy() function. 8: Once all images are downloaded, they are immediately placed into a .zip file using exec('zip -n jpg fbpictures *long file list outputted from the array*');. As soon as exec() finishes, the photos are deleted, leaving only the .zip file in the directory. 9) After all of this finishes, the download link for the .zip file is made visible to the user. This link goes to getdl.php. 10) In getdl.php, the .zip file is retrieved based on your Facebook user ID, which was stored in a cookie eariler ($_SESSION[’session_uid’]). Once the file finishes downloading, it is immediately deleted in order to save space on my server, and to protect your privacy.
How the Friends List Works
Since facebook.friends.get returns the user ID’s of your friends, this list must be parsed and more API calls must be made in order to retrieve their whole names. In order to save time and bandwidth, the first time this function is called, it saves the friend list to a session array, which then gets called each subsequent time instead of making the API calls again. Here’s the code that handles this and outputs it to a dropdown list:
function getFriendsList()
{
GLOBAL $facebook;
echo "n”;
if(!isset($_SESSION[’friends’]))
{
$userids = $facebook->api_client->friends_get();
$names = $facebook->api_client->users_getInfo($userids, array(”name”));
$i = 0;
foreach($names as $name)
{
echo “n”;
$_SESSION[’friends’][$i][’name’] = $name[’name’];
$_SESSION[’friends’][$i][’uid’] = $name[’uid’];
$i++;
}
}
else
{
foreach($_SESSION[’friends’] as $friend)
{
echo “n”;
}
}
}
That just about does it for now, if you have any technical questions, feel free to ask them and I’ll try to answer them to the best of my ability.
Is there an API for getting Wall count and Wall data?? The latest version of the API does not seem to have this, however, there are examples over the net that show some methods
Example: facebook->api_client->wall_getCount();
Is there a way I can get the Wall COunt and the Wall Postings via the Facebook REST API?
Thx
-Jarrett
Jarrett said this on September 26th, 2007 at 1:46 pm
I think in order to do this, some people have written their own methods in order to access that data. I’m not sure off the top of my head how they did it, but they might of used FQL.
Ryan LeFevre said this on October 5th, 2007 at 12:14 pm