Upgrading to Facebook PHP SDK v5 with public API requests
I have just upgraded an application that connects to the Facebook API to the newest PHP SDK
I used the upgrade guide referenced on Github, which mostly did the trick:
Upgrading the Facebook PHP SDK from v4.0 to v5www.sammyk.me
There was one issue though that I had to search around a bit for so I thought it was worth putting in a blog post.
My application only reads from publicly available Facebook pages and therefore does not require a user login, but all requests required an access-token parameter.
The upgrade guide explains how to get an access-token if you want to authenticate a user but there is nothing about generating one without a user logging in.
It’s actually very simple:
$fb = new Facebook([…]);
$accessToken = $fb->getApp()->getAccessToken();