Whether you’re developing a trang web with Facebook login, creating a Facebook Canvas tiện ích or Page tab, the Facebook SDK for PHP does all the heavy lifting for you making it as easy as possible khổng lồ deeply integrate into the Facebook platform.
Bạn đang xem: Facebook sdks
The Facebook SDK for PHP provides a native interface to lớn the Graph API & Facebook Login.PHP SDK Basics
Whether you’re developing a website with Facebook login, creating a Facebook Canvas phầm mềm or Page tab, the Facebook SDK for PHP does all the heavy lifting for you making it as easy as possible lớn deeply integrate into the Facebook platform.Autoloading & namespaces
The Facebook SDK for PHP v5 is coded in compliance with PSR-4. This means it relies heavily on namespaces so that class files can be loaded for you automatically.
It would be advantageous to familiarize yourself with the concepts of namespacing and autoloading if you are not already acquainted with them.
There are two methods lớn install the Facebook SDK for PHP. The recommended installation method is by using Composer. If are unable to lớn use Composer for your project, you can still install the SDK manually by downloading the source files and including the autoloader.
System requirementsPHP 5.4 or greaterComposer (optional) – Composer is a tool for dependency management in PHP. It allows you to lớn declare the libraries your project depends on và it will manage (install/update) them for you.Installing with Composer
The Facebook SDK starting adhering lớn SemVer with version 5. Previous to lớn version 5, the SDK did not follow SemVer. Composer is the recommended way to install the Facebook SDK for PHP. Simply run the following in the root of your project.
composer require facebook/graph-sdk
Once you bởi this, composer will edit your composer.json file and tải về the latest version of the SDK & put it in the /vendor/ directory.
Make sure khổng lồ include the Composer autoloader at the đứng đầu of your script.
require_once __DIR__ . ‘/vendor/autoload.php’;Manually Installation
First, tải về the source code and unzip it wherever you lượt thích in your project.
Download the SDK for PHP v5 at liên kết – https://github.com/facebook/php-graph-sdk/archive/5.4.zip
Then include the autoloader provided in the SDK at the top of your script.
require_once __DIR__ . ‘/path/to/php-graph-sdk/src/Facebook/autoload.php’;
The autoloader should be able lớn auto-detect the proper location of the source code.
The source code includes myriad files that aren’t necessary for use in a production environment. If you’d like to strip out everything except the bộ vi xử lý core files, follow this example. For this example we’ll assume the root of your trang web is /var/html.
After downloading the source code with the button above, extract the files in a temporary directory.
Move the folder src/Facebook khổng lồ the root of your trang web installation or where ever you lượt thích to put third-party code. For this example we’ll rename the Facebook directory to lớn facebook-sdk-v5.
The path the chip core SDK files should now be located in /var/html/facebook-sdk-v5 & inside will also be the autoload.php file.
Assuming we have a script called index.php in the root of our web project, we need lớn include the autoloader at the vị trí cao nhất of our script.
require_once __DIR__ . ‘/facebook-sdk-v5/autoload.php’;
If the autoloader is having trouble detecting the path khổng lồ the source files, we can define the location of the source code before the require_once statement.
define(‘FACEBOOK_SDK_V4_SRC_DIR’, __DIR__ . ‘/facebook-sdk-v5/’);