Skip to content
Advertisement

Facebook Graph API PHP SDK v4 – Post on Page

I wanna give all my website authors a possiblity to post their articles on our facebook page without having go give them admin access to it.

So i created a simple form, where the author types in: URL, URL to image, message

On submit, this form will send a ajax request to facebook.php where the magic “should” happen.

The first problem occurs at “require_once”. It’s not possible to require all 4 files without having an error. If i get rid of the facebook exception, then everything works except the request itself. There seems to be an PHP Error, because i get no ajax response at all.

JavaScript

Advertisement

Answer

Update: June, 27 2014, The SDK now comes with a built-in autoloader for those who can’t use composer.

JavaScript

If that doesn’t automatically find the path for you, you can define it with FACEBOOK_SDK_V4_SRC_DIR.

JavaScript

The internals of the SDK rely on several other classes that you’re not including. That’s why autoloading is really important here.

Autoloading With Composer

The best way to do this is to install composer. And add the SDK in a composer.json file to the root of your project.

JavaScript

Then run composer install from the command line where the composer.json file is. Then include the autoloader at the top of your script.

JavaScript

Manual Autoloading

An alternative way to autoload these files is to replace your require_once‘s at the top with this solution from rm-vanda:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement