Facebook API photos.Get – Querying photos by UID

Technorati Tags:

Just recently, I complained a bit to Facebook about this page of their API: http://wiki.developers.facebook.com/index.php/Photos.get

Why?  Because it was not clear to me how to pass the UserID to the HttpWebRequest in order to query all photos by that UserID.

For example, if you took a look at the description of parameters for the photos.Get method call (before they changed it), you saw the following:

Parameters

Required

Name

Type

Description

required

api_key

string

The application key associated with the calling application.

session_key

string

The session key of the logged in user.

call_id

float

The request's sequence number. Each successive call for any session must use a sequence number greater than the last. We suggest using the current time in milliseconds, such as PHP's microtime(true) function.

sig

string

An MD5 hash of the current request and your secret key, as described in the How Facebook Authenticates Your Application.

v

string

This must be set to 1.0 to use this version of the API.

subj_id

int

Filter by photos tagged with this user. You must specify at least one of subj_id, aid or pids. The subj_id parameter has no default value, but if you pass one, it must be the user's user ID.

aid

string

Filter by photos in this album. You must specify at least one of subj_id, aid or pids. The aid parameter has no default value. The aid cannot be longer than 50 characters.

pids

array

Filter by photos in this list. This is a comma-separated list of pids. You must specify at least one of subj_id, aid or pids. The pids parameter has no default value.

optional

format

string

The desired response format, which can be either XML or JSON. (Default value is XML.)

callback

string

Name of a function to call. This is primarily to enable cross-domain javascript requests using the <script> tag, sometimes known as "JSONP". This works with both XML and JSON.

Now where would I pass the uid I thought?  I am not using FQL at the moment (just API calls instead to do the same) so I did not really care to scroll down further because I knew all their pages dive into FQL at that point mostly.  I scrolled only enough to get to the FQL and back up.  But eventually I decided to hunt further since I saw no way of passing a uid to the request, and found the following FQL:

SELECT pid, aid, owner, src, src_big, src_small, link, caption, created 
FROM photo WHERE pid IN (SELECT pid FROM photo_tag WHERE subject=<uid>) 
AND aid=<aid> AND pid IN (pid)

Notice the subject=<uid>

I scrolled back up and thought ok, must be the equivalent to the method param called subj_id because it stated “this user” in its description which I equate to uid in my head.

If I had not taken a look at the FQL below it, and had Facebook not included that particular field check in the FQL example (which knowing their docs is completely possible) I’d be screwed.  I would have had no idea how or if the uid could be passed.

So luckily after I brought this to their attention, they changed it to:

“subj_id int
Filter by photos tagged with this user. You must specify at least one of
subj_id, aid or pids. The subj_id parameter has no default value, but if you pass one, it must be the user's user ID.”

Some developers can document, and some just cannot or it’s that they do not make an effort or care how it comes across.  The sentence is such a run-on and just is weird wording.  it leaves me with these questions:

     > Why is there no uid when most of the methods in the Facebook API take a uid? 

     > What does sub_id have to do with uid?  Weird.  I found out later that uid is appended to sub_id after reviewing my Facebook account.

The way I would have worded it was (I added in green):

“subj_id int
Filter by photos tagged with this user. You must specify at least one of
subj_id, aid or pids. The subj_id parameter has no default value. 

Note: While most Facebook API method calls take a uid, we use subj_id as the means to query photos based on a specific userID. 

You will receive back only those photos found in that user’s “Photos of <uid’s name>” section of Facebook

image

Using this parameter will not retrieve all photos across all albums.  For this, you must pass all Album aids into a request to photos.get instead.

Now you’re thinking wow man, that’s a lot of text dude.  Sure…to some it may be, but it’s not really that much honestly.  But it clearly explains to you what’s going on with that parameter since it DOES relate to uid…who would ever know.  And if it’s a lot, then hey, shove the remainder into an expandable JQuery control then and hide it.  But surely show detailed information like this.

This I figured out pretty quickly on my own to be honest (within a few minutes) just from pure observation of everything on their page, but in most circumstances you spend hours trying to figure out how to use the Facebook API.  And some developers may not put that puzzle together as quickly as you or I did so details are useful.

I’ve gotten my implementation of Facebook working for a current project I’m working on.  But it sure could have been much less painful if Facebook would have decent documentation and sentences that make sense, don’t stop in the middle, and give more explanation to the process of calls, POSTs, and much more.

I encourage you to complain to Facebook if their current documentation is not adequate.  They seem to be open to improving so provide them with the link and how it can be improved.  There are many pages you just cannot edit in the wiki.  As one who likes to help the community, I was tempted to edit it many times.

With that, I hope to contribute more here on my blog providing better explanations or tips in the near future as it pertains to Facebook in general and Facebook with .NET.


Print | posted on Tuesday, February 10, 2009 8:43 PM

Comments on this post

# re: Facebook API photos.Get – Querying photos by UID

Requesting Gravatar...
Unfortunately, leaving out method arguments are the least of my issues with the facebook api documentation. They like to drop little hints here and there in their run-on sentences and never elaborate on a feature they may have mentioned. Makes for *a lot* of trial and error, and wasted time.

I've already had to actually edit the distributed facebook php5 rest api client code in several places to fix bugs / make api calls work as "intended" (or at least, described) in the documentation.

Another one of my issues with the whole thing, is that there is no standard way to check if a user's facebook session is still active - their solution is to "just call a method which requires session access" - makes for some random code and a lot of "WTF?" when you try to read the code later. "Why in the F are we trying to figure out a list of photo albums for our user here, and never use them?!"

sigh.
Left by Jim on Feb 11, 2009 10:08 AM

# re: Facebook API photos.Get – Querying photos by UID

Requesting Gravatar...
>>Unfortunately, leaving out method arguments are the least of my issues with the facebook api documentation.

True, but it's all these little things that add up to making working with the API a pain in the royal ass.

The worst part is, besides the docs being bad...the forum administrators who respond are horrible. They either respond with "it looks clear to me" or "why would you want to do that" or "well just test and you'll see" as if we have all day to test their missing information that are rudamental technical facts needed to use the damn system.

Worse, they give you the answer you need (which is rare and only usually happens after you bitch about their lazy responses) but it clearly should have been in the docs all along. I'm talking simple rudamental API dependencies and facts that developers would not know because we did not build this API.
Left by Dave Schinkel on Feb 11, 2009 7:41 PM

# re: Facebook API photos.Get – Querying photos by UID

Requesting Gravatar...
the documentation is very confusing, agreed.
im trying to just display a picture from a pid query. there is NO support on how to do this stuff.

any ideas?
Left by lee on May 05, 2009 4:17 PM

# re: Facebook API photos.Get – Querying photos by UID

Requesting Gravatar...
What gets me is that I have to dig through half way through the page to figure out the return value of the API call.

Honestly, wouldn't you expect a binary image to be returned and not its URL?


Left by David on May 10, 2009 11:43 AM

# re: Facebook API photos.Get – Querying photos by UID

Requesting Gravatar...
This method is a wrapper for the FQL query on the comment FQL table. photos.get: Returns all visible photos according to the filters specified. photos... getTags: Returns the set of user tags on all photos specified. ... getLoggedInUser: Gets the user ID ( uid ) associated with the current session.
If you specify the API key in your client, you don't need to pass it with every call. For get all photos of a user, given its uid.

----------------------------------------------

Left by ccindy82 on Sep 11, 2009 1:37 AM

Your comment:

 (will show your gravatar)
 
Please add 1 and 6 and type the answer here: