简体   繁体   中英

How to handle facebook API version upgrade exception dynamically

I've been using facebook graph API from quite a long time. One problem i'm facing frequently is API version upgrade exception as shown below for every 3months:

message - (#2635) You are calling a deprecated version of the Ads API. Please update to the latest version: v2.7. code - 2635 Relevant information for error recovery can be found on the Facebook Developers Document:
        https://developers.facebook.com/docs/graph-api/using-graph-api/#errors

FacebookException{statusCode=400, errorType='OAuthException', errorMessage='(#2635) You are calling a deprecated ver sion of the Ads API. Please update to the latest version: v2.7.', errorCode=2635, errorSubcode=-1, version=2.4.6}

Due to this, i need to update the version in properties file everytime which i'm reading in my java code and needs to get deployed it in production. Though there are no changes in the APIs i'm using, i'm forced to do this change everytime.

i have 3 fixes in mind for now to avoid the deployment again and again:

1) Read the API version from database and give update script to production whenever version gets changed.

2) Poll the properties file for any modification and read again if it gets modified.

3) Dirty fix: catch the exception, parse the version from exception string and update the URL dynamically.

But i'm thinking is there any other better way to get latest FB API version dynamically and use it to avoid these changes frequently and also i want to know how others handle this in their applications?

From the error message you got it seems that the Ads API you are using (version 2.4.6) is deprecated.

From this page the Ads API is part of Marketing API . Although the Marketing API 's versioning documentation states that the old API is deprecated after 90 days and you cannot call that version later but from the Facebook Platform Changelog (Marketing API's table) you can see that deadlines are no so strict: if you start to use version 2.7 you are fine until April 2017 and with version 2.8 even more (not specified at this moment).

So it seems that you cannot avoid versioned calls in Marketing API and you have to update your code regularly but with using the latest version you do not have to update for around a year.

Disclaimer: It is just speculation I have no experience with the Facebook API.

It is simply not possible to dynamically update the Facebook API versions without changing your code, that's why it is called: "Facebook Breaking Changes". Sometimes the model will change, sometimes the URL signature, but there will almost always be something that will require a change to how you utilize or handle the response of the API in your code.

Facebook updates their apis consistently and you will need to thoroughly review the documentation they provide (which you should be wary that it is often not 100% accurate) and then make the necessary changes as soon as you can.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM