Access public pictures without an access token?

2019-08-19 04:43发布

问题:

I created a php module for Drupal that pulls a public album and display pictures inside it. I discovered that the module suddenly stopped working. I googled and looks like even a public album requires an access token now. I see access token field on https://developers.facebook.com/tools/explorer/?method=GET&path=10150146071791729

In this case, how do I fix this problem? It looks like even offline_access is gone now.

Do I must ask users to accept a certain permission? What permission? It's a public pictures.

回答1:

Ok, found an answer.

You need to create an app and get an app id and a secret key.

Once you have those two, download Facebook PHP SDK on https://github.com/facebook/facebook-php-sdk.

Sample Code:

require_once "facebook.php";

$facebook = new Facebook(array(
  'appId'  => 'appid',
  'secret' => 'securet',
));

$token = $facebook->getAccessToken();

$json = file_get_contents("https://graph.facebook.com/293849234?access_token=".$token);