Facebook iOS: Use Access Token in PHP

Yes that's right. As of the time of this writing, it is possible to use the user granted access_token back in some server side scripting language like PHP. If you currently have a 255 varchar field size for access_tokens in your database, you may want to bump that up a bit.

The time I made the sample code ran and allowed me to log in (one that came bundled with the Facebook iOS SDK from GitHub), I began realizing that the token quite have different format than the one we usually see in web-based apps (e.g. FB iFrame app).

The usual token looks something like this:

213455681425|1.BGgrgnfWrdpG_X18.3600.1213252135.2-1334679|dHcDbxGbeYbLg3SRgw12fdf4gd60

..while in mobile:

v9ylvkttPnuFWUX4KVdjDPB0SRXkuKX7z281rqjHuG0.eyJpdiI6ImEwWXBDaEtncWpDTU5ibUNuQWdROWcifQ.Y-DwxRY2ZAFZiP7EVuR-HksXqmGw9LXP6umGrfz2XnjSLm0a508u7_jXq0_Kz5a2S8AUUulzUvIRVxTS51_i6VfSByOCbFBIKoBe0-n-Pa8NC29wbuVmGJLvq4W-ezhv0DzA3diiCIqCybt9ELDXoA

The plan was, allow users to connect to our application using FB. Then once he approved it, we take a copy of the access_token and save it back to the server. Same access_token will be used once he logs in to his account using our web-based app.

Well, so far so good. Let me know if yours doesn't work.


Related posts:

5 comments :

Magento Modules said...

thanks, can we use same for Magento?

Magento Themes said...

Great idea, will also check on it..

Magento Themes said...

can it be done through database....

bassgrinder said...

Well yes. But that was then when offline_access was still available. Things are different now on this. And you should read the following article and know the things you can do to extend the life of these tokens.

Read on Removal of offline_access permission here: http://developers.facebook.com/roadmap/offline-access-removal/

bassgrinder said...

Can you use the same for Magento? Well yah. I see no problem adopting it to your web app. Just be aware of the current Facebook trends because every now and then, they change stuffs in their platform.

Post a Comment

Hi there! Please leave your message here. Also, I may not be able to respond to your query right away. So please bear with me. Thanks. :)