Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query Facebook for what version of the Graph API is being used / can be used

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)?

like image 457
Metal450 Avatar asked Aug 12 '14 04:08

Metal450


2 Answers

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

  • https://developers.facebook.com/docs/apps/versions#unversioned_calls
  • https://developers.facebook.com/docs/apps/versions#calling_older_versions

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.

like image 59
Tobi Avatar answered Nov 03 '22 07:11

Tobi


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.

like image 23
Jeff Parsons Avatar answered Nov 03 '22 08:11

Jeff Parsons