5

I'm the author of a Wordpress plugin that leverages the Facebook Graph API. Recently, some Graph calls are failing for new plugin users (only new users are affected). After some digging, I believe I've stumbled on the cause here: https://developers.facebook.com/docs/apps/versions

In particular, the section "Can my app make calls to versions older than the current version?" states:

An app can make calls to the version of the API that was the latest available when the app was created

In other words, even if my Graph calls specify an explicit version (i.e. https://graph.facebook.com/v2.0/me), for newly-created apps, Facebook will simply ignore the "v2.0" and call into 2.1. Indeed, an FQL query like:

https://graph.facebook.com/v2.0/fql?q=(myquery)&access_token=(mytoken)

Yields:

"error": { "message": "(#12) fql is deprecated for versions v2.1 and higher", "type": "OAuthException", "code": 12

So that leads to my first question: Am I missing something here? To me, this behavior seems to make versioning pretty much useless; whether or not my calls specify v2.0, Facebook will just call into the newest version that existed when that app happened to have been created. So the two-year time window Facebook gives for supporting old api versions (see https://developers.facebook.com/docs/apps/upgrading) does nothing, as I always need to support the most-current version the moment it's released (or new users with newly-created apps will be broken). Right?

Second question (assuming the above is correct): How can I query Facebook for the version that's being used (or rather, available to be used) by the current app? Since specifying v2.0 clearly doesn't mean it'll actually use v2.0, finding out if it's using an unexpected version could at least help preempt possible errors - i.e. it'd be valuable info to include with user bug reports. I expect that this information must somehow be in the access_token, but I've searched high and low and can't figure out how to ask, "What API version does this token apply to" (or perhaps, "What's API versions does this app support," or similar)?

Tobi
  • 31,405
  • 8
  • 58
  • 90
J23
  • 3,061
  • 6
  • 41
  • 52

2 Answers2

7

You have to distinguish between API versions and App creation. As you correctly stated, Facebook supports older versions of the Graph API exactly 2 years after the successor has been announced.

The docs at https://developers.facebook.com/docs/apps/versions#howlong state

A version will no longer be usable two years after the date that the subsequent version is released.

and

So if API version 2.0 is released on April 30th, 2014 and API version 2.1 is released August 7th, 2014 then v2.0 would expire on August 7th, 2016, two years after the release of v2.1.

What happens if you make calls to the Graph API with no specified version information is the following:

An unversioned call will default to the oldest available version of the API

meaning that it your app was created at August 1st 2014, you'll be able to call v2.0, but not v1.0. If your App was created at April 1st 2014, you'll be able to call v1.0 (but only until v1.0 is deprecated at April 30th 2015). If your App was created later than August 7th 2014, you'll only be able to call v2.1, no matter what you specify as version.

This is outlined at

An app can make calls to the version of the API that was the latest available when the app was created, as well as any newer, un-deprecated versions launched after the app is created.

So, in other words, it always more relevant on what date your Facebook App was created, because this will determine the Graph API version(s) the App will be able to use

To determine the creation date of an App, you can use the

/{app_id}?fields=id,creation_time

endpoint, which will give you the Unix Timestamp when the respective App was created. See https://developers.facebook.com/docs/graph-api/reference/v2.1/app/#readfields You can then use for example PHP or JavaScript to transform the Unix Timestamp to a date.

Tobi
  • 31,405
  • 8
  • 58
  • 90
  • Yeah, I did read all that. It just seems so useless to me that Facebook would be providing a versioned API - and claiming that they allow us to select which version to use - but then not even respecting that selection. – J23 Aug 13 '14 at 09:12
  • Regarding determining version: I suppose looking at the creation date, looking up their release schedule manually in their docs, and using those to infer the API version would work. Sort of. But it seems like an extremely roundabout/poor solution (i.e. what time of day does the app have to be created to be considered pre-release or post-release? And in which timezone)? There should be a much more reliable way to *directly* query which version is actually being used, programmatically - not to guess it from other info (and require a human to read their docs and keep track of release dates). – J23 Aug 13 '14 at 09:15
  • I think it's quite clear from their docs what to do. If you'd read it carefully, you'd understand that you can use the versionned API, but only upwards. This is clearly stated, and from the release dates you can develop a logic for the calls. And, by the Way, I think I answered both your questions – Tobi Aug 13 '14 at 09:40
  • Yep, you did. My comment wasn't with regards to the quality of your answer - just the poor design of the API :) I would like to leave this question open a bit longer though, in case someone can come up with a more programmatic approach (i.e. not requiring a human to read the documentation and keep track of release dates and versions manually)...but if after a bit of time has passed it still seems as though FB offers no reasonable way to do this, of course I'll accept yours :) – J23 Aug 13 '14 at 18:48
  • I can understand that, but I think there's no programmatic way. The Graph API is unfortunately not really complete at some points, and IMHO it's even getting worse from version to version. – Tobi Aug 14 '14 at 16:48
  • I agree 100%. If I knew from the get-go how awful their documentation, maintenance, breakage, etc habits were...I would never have built something on their platform. I'd honestly say that a good 25%+ of my plugin issues arise from spontaneous/unannounced changes or bugs (which users berate me for, and in the latter case, I can often do nothing but wait for Facebook to get off their asses and fix it :P) – J23 Aug 15 '14 at 01:26
  • Looks like nobody has stepping in, which I'll presume means this is likely the best approach Facebook provides for now. Accepted. – J23 Jan 12 '15 at 02:31
2

Note that the ability to check the age of the app has changed slightly. It is now:

/{app_id}?fields=id,created_time

It also now gives back an actual timestamp

{ "id": "12341234123412341234fake", "created_time": "2011-11-30T21:00:56+0000" }

A simple way to test this manually is via the Graph API Explorer here: https://developers.facebook.com/tools/explorer/

Just be sure to select the right app and an app token.

Jeff Parsons
  • 99
  • 1
  • 3