Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here

facebook-php-sdk-v4

The Facebook SDK for PHP provides a native interface to the Graph API and Facebook Login. https://developers.facebook.com/docs/php

Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star blank 374f33e4d622a2930833db3cbea26b5d03dc44961a6ecab0b9e13276d97d6682Star blank 374f33e4d622a2930833db3cbea26b5d03dc44961a6ecab0b9e13276d97d6682 (1 ratings)
Rated 3.0 out of 5
Subscribe to updates I use facebook-php-sdk-v4


Statistics on facebook-php-sdk-v4

Number of watchers on Github 2077
Number of open issues 27
Average time to close an issue 17 days
Main language PHP
Average time to merge a PR 4 days
Open pull requests 60+
Closed pull requests 39+
Last commit over 1 year ago
Repo Created over 5 years ago
Repo Last Updated over 1 year ago
Size 1.85 MB
Organization / Authorfacebook
Contributors45
Page Updated
Do you use facebook-php-sdk-v4? Leave a review!
View open issues (27)
View facebook-php-sdk-v4 activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating facebook-php-sdk-v4 for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)
What people are saying about facebook-php-sdk-v4 Leave a review
live

Facebook SDK for PHP (v5)

Build Status Scrutinizer Code Quality Latest Stable Version

This repository contains the open source PHP SDK that allows you to access the Facebook Platform from your PHP app.

Installation

The Facebook PHP SDK can be installed with Composer. Run this command:

composer require facebook/graph-sdk

Please be aware, that there are issues when using the Facebook SDK together with Guzzle 6.x. php-graph-sdk v5.x only works with Guzzle 5.x out of the box. However, there is a workaround to make it work with Guzzle 6.x.

Upgrading to v5.x

Upgrading from v4.x? Facebook PHP SDK v5.x introduced breaking changes. Please read the upgrade guide before upgrading.

Usage

Note: This version of the Facebook SDK for PHP requires PHP 5.4 or greater.

Simple GET example of a user's profile.

require_once __DIR__ . '/vendor/autoload.php'; // change path as needed

$fb = new \Facebook\Facebook([
  'app_id' => '{app-id}',
  'app_secret' => '{app-secret}',
  'default_graph_version' => 'v2.10',
  //'default_access_token' => '{access-token}', // optional
]);

// Use one of the helper classes to get a Facebook\Authentication\AccessToken entity.
//   $helper = $fb->getRedirectLoginHelper();
//   $helper = $fb->getJavaScriptHelper();
//   $helper = $fb->getCanvasHelper();
//   $helper = $fb->getPageTabHelper();

try {
  // Get the \Facebook\GraphNodes\GraphUser object for the current user.
  // If you provided a 'default_access_token', the '{access-token}' is optional.
  $response = $fb->get('/me', '{access-token}');
} catch(\Facebook\Exceptions\FacebookResponseException $e) {
  // When Graph returns an error
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(\Facebook\Exceptions\FacebookSDKException $e) {
  // When validation fails or other local issues
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}

$me = $response->getGraphUser();
echo 'Logged in as ' . $me->getName();

Complete documentation, installation instructions, and examples are available here.

Tests

  1. Composer is a prerequisite for running the tests. Install composer globally, then run composer install to install required files.
  2. Create a test app on Facebook Developers, then create tests/FacebookTestCredentials.php from tests/FacebookTestCredentials.php.dist and edit it to add your credentials.
  3. The tests can be executed by running this command from the root directory:
$ ./vendor/bin/phpunit

By default the tests will send live HTTP requests to the Graph API. If you are without an internet connection you can skip these tests by excluding the integration group.

$ ./vendor/bin/phpunit --exclude-group integration

Contributing

For us to accept contributions you will have to first have signed the Contributor License Agreement. Please see CONTRIBUTING for details.

License

Please see the license file for more information.

Security Vulnerabilities

If you have found a security issue, please contact the maintainers directly at me@sammyk.me.

facebook-php-sdk-v4 open issues Ask a question     (View All Issues)
  • almost 3 years Invalid JSON response kills script when user is blocked from posting
  • almost 3 years how to get the likes count of a facebook page in v2.8 using php-graph-sdk?
  • almost 3 years please how can i get the user email
  • almost 3 years opportunity to Cancel user subscription
  • almost 3 years OAuthException 191
  • almost 3 years Convert docs to standard markdown
  • about 3 years Switch default branch to 5.4
  • about 3 years [6.0] Add acceptance tests with Behat
  • about 3 years FacebookBatchResponse failed
  • over 3 years Remove helpers and make use of a string access token/signed request
  • over 3 years Remove the Facebook prefix from nearly all classes
  • over 3 years Force the user to choose a Graph API version
  • over 3 years Use HTTPlug instead of our HTTP clients
  • over 3 years PSR-4 and flat directory structure
  • over 3 years [6.0] Roadmap
  • over 3 years Issue unlinking image file
  • over 3 years Facebook network is unreachable
  • almost 4 years Example snippets show PHP SDK v4.0 API
  • over 4 years [6.0][Proposal] Define the SDK API
  • over 4 years [6.0][Proposal] Remove Collection class
  • over 4 years [6.0] Batch Request support for omit_response_on_success
  • over 4 years [6.0][Proposal] Refactor Graph nodes
  • over 2 years Video Upload and "find the Videos"
  • over 2 years auto post problem
  • over 2 years Problem with endpoint /{album-id}/photos
  • over 2 years [6.0] Add ability to define MIME type for file upload
  • over 2 years photos upload using batch request to timeline not working
  • almost 3 years Only "data" key is casted to GraphNode
facebook-php-sdk-v4 open pull requests (View All Pulls)
  • 4.0 dev
  • Update the GraphAlbum
  • Update get method to support parameters
  • Making sure that AccessToken::__toString returns string
  • Add better error checking for app IDs as int when greater than PHP_INT_MAX
  • 4.1 dev
  • Use Composer safe versions
  • Updated copyright year from 2014 to 2016.
  • Remove mb-string dependency
  • Updating logic for x_forwarded_host
  • Implementing new Birthday class to handle Graph API response variations
  • Bump Graph version to v2.6
  • Update README.md, correctly reference Facebook Class
  • fixed issue#598
  • FacebookRedirectLoginHelper - let's not regenerate CSRF token
  • Update FacebookUrlDetectionHandler.php
  • Add fix for #619
  • Remove backwards support for PHP < 5.6
  • Remove autoloader
  • Replace custom CSPRNG with random_compat
  • Remove default Graph API version fallback
  • Removed the HTTP layer and started to use HTTPlug
  • FacebookRequest:setAccessToken(): phpdoc update: accepts null as an argument
  • Fix the composer master branch alias for 6.0
  • [WIP] Convert docs to Markdown
  • Update CSPRNG factory
  • Update SignedRequest.php
  • Fix: Use double pipe for specifying alternate PHP versions
  • Fix: Apply PSR-2 to credentials template
  • Enhancement: Require latest version of phpunit/phpunit
  • Fix: Use class keyword
  • Fix: Use more appropriate assertions
  • Fix: Remove unused imports
  • Fix: Provide more specific docblock
  • Fix: Remove useless override
  • Fix: Run build on PHP7.1
  • Enhancement: Keep packages sorted without specifying --sort-packages
  • Add full batch support without BC breaks
  • Implement omit_response_on_success batch option
  • add link to RapidAPI
  • Cache size of the array
  • Update AccessToken.php
  • Use filter_var instead of regex (preg_match)
  • Generate Better OpCode
  • Added stop_time to the shouldCastAsDateTime whitelist array
  • Allowing response_type to be overriden for authorization url retrieval
  • Strip 'code' param
  • Clean up documentation files
  • Rework GraphNode API
  • Update FacebookRedirectLoginHelper.php
  • Added possibility to choose the login display type
  • Added Hack Compatibility
  • Fix loose of information when GraphNode convertion
  • getFanCount() method to GraphPage. (get pagelikes)
  • Fix PHPDoc wrong type
  • [WIP] Remove helpers
  • TODO v 6.0
  • Add 'joined' field to cast in DateTime
  • added post status update example
  • Adding `postJson` to support endpoints that expect 'application/json'.
facebook-php-sdk-v4 questions on Stackoverflow (View All Questions)
  • facebook login wiht use facebook-php-sdk-v4-5.0.0 connect timed out
  • Facebook PHP SDK v4: AccessToken->getExpiresAt() does not return correct time
  • Facebook php sdk-v4~5.0@dev could not find user is logged in or not
  • Facebook php sdk v4 get unlimited messages from user inbox
  • Facebook PHP sdk-v4-5.0 Cannot Upload Photos Except those of Developer
  • Unknown path components - Facebook PHP SDK v4
  • Class 'FacebookSession' not found - Facebook PHP SDK v4
  • Facebook PHP SDK v4 return blank page on server but working in localhost
  • (#322) Subject does not have permission to tag this photo - Facebook PHP SDK v4
  • Error when posting image with Facebook PHP SDK v4
  • Facebook PHP SDK v4 - Proper folder structure anyone?
  • Facebook PHP SDK v4 $session NULL after login
  • Facebook PHP SDK V4: two login buttons
  • Using facebook-php-sdk-v4 to do a resumable upload of video to facebook
  • Facebook PHP SDK v4: isValidRedirect() always return false
  • Is there a way to get facebook response in Json or array format with Facebook PHP SDK V4?
  • Facebook-php-sdk v4
  • Facebook php-sdk v4 get friends ID
  • How to import the facebook php sdk v4 in cakephp 2.4.?
  • Facebook PHP SDK v4 get current accessToken
  • Facebook PHP SDK v4 - Post to page feed not showing correctly
  • Facebook php-sdk v4 get friend list
  • Facebook PHP SDK v4 - Getting back only page's scheduled posts
  • how to publish post on facebook page wall as admin using facebook php sdk v4 and graph api 2.x
  • How to access user languages inside GraphObject using Facebook PHP SDK v4
  • An active access token must be used to query information about the current user. Facebook PHP SDK v4
  • How to get posts from my Facebook profile page using Facebook PHP SDK v4?
  • How to set permissions using facebook/php-sdk-v4
  • how to integrate facebook PHP SDK (v4) to my ZF1 site
  • Graph API v1.0 from Facebook-PHP-SDK v4
facebook-php-sdk-v4 list of languages used
Other projects in PHP