This repository contains the xuất hiện source PHP SDK that allows you lớn access the Facebook Platform from your PHP app.
Bạn đang xem: The facebook sdk for php provides a native interface to the graph api and facebook login
InstallationThe Facebook PHP SDK can be installed with Composer. Run this command:
Upgrading to lớn v5.xUpgrading from v4.x? Facebook PHP SDK v5.x introduced breaking changes. Please read the tăng cấp guide before upgrading.
UsageNote: 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 FacebookFacebook(< "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 FacebookAuthenticationAccessToken entity.// $helper = $fb->getRedirectLoginHelper();// $helper = $fb->getJavaScriptHelper();// $helper = $fb->getCanvasHelper();// $helper = $fb->getPageTabHelper();try // Get the FacebookGraphNodesGraphUser object for the current user. // If you provided a "default_access_token", the "access-token" is optional. $response = $fb->get("/me", "access-token"); catch(FacebookExceptionsFacebookResponseException $e) // When Graph returns an error echo "Graph returned an error: " . $e->getMessage(); exit; catch(FacebookExceptionsFacebookSDKException $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, & examples are available here.
TestsThe tests can be executed by running this command from the root directory:
By default the tests will send live HTTP requests to the Graph API. If you are without an mạng internet connection you can skip these tests by excluding the integration group.
LicensePlease see the license tệp tin for more information.
Security VulnerabilitiesIf you have found a security issue, please contact the maintainers directly at
Hi, I"ve moved to the latest version of the SDK and tried the simple login example for starters and it was working fine a few days ago. However I now get the following error:
Facebook SDK returned an error: Cross-site request forgery validation failed. Required param "state" missing.
I can"t figure out the problem, I"ve had a look at the following section of the Helper.
/** * Validate the request against a cross-site request forgery. * *
throws FacebookSDKException */protected function validateCsrf(){ $state = $this->getState(); $savedState = $this->persistentDataHandler->get("state"); if (!$state || !$savedState) throw new FacebookSDKException("Cross-site request forgery validation failed. Required param "state" missing."); $savedLen = strlen($savedState); $givenLen = strlen($state); if ($savedLen !== $givenLen) throw new FacebookSDKException("Cross-site request forgery validation failed. The "state" param from the URL and session do not match."); $result = 0; for ($i = 0; $i
This will fix #605, it is also related to #586.
This is a truyền bá in order khổng lồ better support PSR7 in this library by using HTTPlug abstraction. By using HTTPlug a lot of code can be removed & the maintenance will be more focus on the graph API và not the HTTP transport layer (as you can see the diff, a lot of code is no longer necessary).
Shared work: Many libraries already implement HTTPlug or are on the way, this mean, we can better profit for feature offered / wanted by other libraries.
One could go further with PSR-7. I"ve chosen lớn stop here for this PR. But possible future work could be:
Removing the FacebookResponse & FacebookRequestRemove RequestBodyUrlEncoded và RequestBodyInterfaceRemove FacebookClient::getHttpClientThe official docs demonstrate some sub-classes lượt thích GraphUser, & the code have another unmentioned classes lượt thích GraphAlbum, and many other types still haven"t classes at all.
I just want to lớn ask about your plan khổng lồ offer a complete set of GraphObject sub-classes? và if you have any plan to support Edges in addition khổng lồ the Fields?
I"m really interested to contribute in these points, but I need to lớn hear from you before I showroom any pull requests?
When i am trying khổng lồ login with facebook on my site, after facebook login it throwing
Graph returned an error : Can"t Load URL: The tên miền of this URL isn"t included in the app"s domains. Lớn be able khổng lồ load this URL, showroom all domains and subdomains of your tiện ích to the ứng dụng Domains field in your ứng dụng settings.
It was working fine two days ago. Today one of my user told me regarding this and when i checked it is throwing error after facebook login.
What is the problem và how vì I fix it? I"ve searched, và found many similar posts, but none of them have a solution that I can figure out how lớn apply.
Thanx for help in advance
Hi Guys,
Facebook shipped a Resumable đoạn phim upload api(https://developers.facebook.com/docs/graph-api/video-uploads) on F8, which will helps clip publisher khổng lồ achieve a more reliable uploading experience. In order to lớn simplify the developer work, we want to add a helper class in php sdk, which will receive the single video file, cut it into small chunks and feed facebook chunked uploading api.
We already địa chỉ this functionality into Facebook python sdk(https://github.com/facebook/facebook-python-ads-sdk/blob/master/facebookads/video_uploader.py). And currently want to have the same thing in php sdk with our July release.
Xem thêm: Mytv Là Gì ? Cách Đăng Ký Dịch Vụ My Tv Nhanh Nhất Những Gì Bạn Muốn
YuanhuiChen is working on this new sdk api right now. Https://github.com/facebook/facebook-php-sdk-v4/pull/452
SammyK just kindly noticed me that we didn"t kick any discussion for this sdk api interface yet. I"m sorry. It is our mistake. But would lượt thích to start the discussion now and keep everyone in the same page.
Could you guys take a look at this diff and give us your insight feedbacks?
Thanks a lot,Lei
Phew! OK, let"s see everyone can agree on this setup. :) This isn"t 100% 4.1 feature packed but we can use it as a good starting point if everything is OK.
SetupTo make a request to Graph, you need lớn instantiate a new FacebookApp to lớn hold your tiện ích config. You"ll also need a FacebookClient to lớn send request entities lớn Graph.
use FacebookEntitiesFacebookApp;use FacebookFacebookClient;$facebookApp = new FacebookApp("app-id", "app-secret");$facebookClient = new FacebookClient(/* $httpClientHandler, $enableBeta */);Simple GET Requestuse FacebookEntitiesFacebookRequest;$request = new FacebookRequest($facebookApp, "access-token", "GET", "/me"/*, $params, $eTag, $graphVersion */);$facebookResponse = $facebookClient->sendRequest($request);$userProfile = $facebookResponse->getGraphObject();Simple POST Requestuse FacebookEntitiesFacebookRequest;$request = new FacebookRequest($facebookApp, "access-token", "POST", "/me/feed", <"message"=>"Foo message!">/*, $eTag, $graphVersion */);$facebookResponse = $facebookClient->sendRequest($request);$data = $facebookResponse->getDecodedBody();$id = $data<"id">;Simple DELETE Requestuse FacebookEntitiesFacebookRequest;$request = new FacebookRequest($facebookApp, "access-token", "DELETE", "/some-id"/*, $params, $eTag, $graphVersion */);$facebookResponse = $facebookClient->sendRequest($request);$data = $facebookResponse->getDecodedBody();$wasSuccessful = $data<"was_successful">;Batch Request Setupuse FacebookEntitiesFacebookBatchRequest;$batchRequest = new FacebookBatchRequest(/* $facebookApp, "access-token", <$requests>, $graphVersion */);Three ways to địa chỉ cửa hàng requests lớn batch request
$app = new FacebookApp("123", "foo_app_secret");$helper = new FacebookRedirectLoginHelper($app);AccessTokenThe AccessToken entity requires FacebookApp & FacebookClient for requests that gọi Graph. For example:
$accessTokenFromCode = AccessToken::getAccessTokenFromCode("foo_code", $app, $client);I think this could be done better for the future. I"d like to simplify the AccessToken entity khổng lồ only hold data about the access token. Và any calls khổng lồ graph could be done with a FacebookAccessTokenHelper. What bởi you guys think?
Simplified FacebookHttpClientInterfaceI also simplified the FacebookHttpClientInterface so that the request headers could be sent as an argument in the send() method.
Integration Tests LabledThe tests that actually touch Graph are labeled "integration". So you can run the demo suite with:
$ phpunit --exclude-group integrationAnd it won"t touch the live version of Graph. So now we can incorporate Travis CI without any issues! :)
TODOFor the next few PR"s:
Factories lớn make FacebookRequest"s và FacebookBatchRequest"sCollections on GrahObjectAdding GraphList with paginationHey Guys,
I"m developing my trang web ---- and I"m having an issue with my Facebook callback page. I"m getting this error: Facebook SDK returned an error: Cross-site request forgery validation failed. The "state" param from the URL and session vị not match..
I was reading Facebook PHP SDK and I found that when you hotline $fb->getRedirectLoginHelper() a new value for $_SESSION<"FBRLH_state"> will be assigned so when I call it again on my callback (because I need to lớn get the accessToken) , a error will happen because ($_SESSION<"FBRLH_state"> != $_GET<"state">);
https://github.com/facebook/facebook-php-sdk-v4/blob/master/src/Facebook/Helpers/FacebookRedirectLoginHelper.php
public function __construct(OAuth2Client $oAuth2Client, PersistentDataInterface $persistentDataHandler = null, UrlDetectionInterface $urlHandler = null, PseudoRandomStringGeneratorInterface $prsg = null) $this->oAuth2Client = $oAuth2Client; $this->persistentDataHandler = $persistentDataHandler ?: new FacebookSessionPersistentDataHandler(); $this->urlDetectionHandler = $urlHandler ?: new FacebookUrlDetectionHandler(); $this->pseudoRandomStringGenerator = PseudoRandomStringGeneratorFactory::createPseudoRandomStringGenerator($prsg); Index page:
$fb = $this->facebook;$helper = $fb->getRedirectLoginHelper();$permissions = <"email","public_profile","user_friends">;$loginUrl = $helper->getLoginUrl("https://fleacollege.com/login/facebook", $permissions);//passing url from controller to lớn view :$this->view->facebookURL = $loginUrl;Callback page:
$fb = $this->facebook;$helper = $fb->getRedirectLoginHelper();try $accessToken = $helper->getAccessToken(); catch(FacebookExceptionsFacebookResponseException $e) // When Graph returns an errorecho "Graph returned an error: " . $e->getMessage();exit; catch(FacebookExceptionsFacebookSDKException $e) // When validation fails or other local issuesecho "Facebook SDK returned an error: " . $e->getMessage() . "";exit;$accessToken = $helper->getAccessToken();echo $_SESSION<"FBRLH_state"> . "";echo $_GET<"state">;return from echo:
e7fca1bfcb37fe3262468c068b72a3dee0eec1b15428c9429846d2b41753473fAnyone know why this is happening? I just followed https://developers.facebook.com/docs/php/howto/example_facebook_login/5.0.0
Hi,I"m using the latest version of the sdk (5.5.0)I"ve unset the appsecret_proof in the ứng dụng advanced config, but when I use a valid access token got directly from the api tools. But I get all the time the next error:
Invalid appsecret_proof provided in the API argument
This is a code issue, due I"m using the main README.md code that should works but don"t. Please, check it & fix it this, so we can not use que facebook until now.
I am trying to use the batch upload to work with photos but I am getting an error.
For some reason it uploads the first photo but the other photos throw an error.
Is there a quick guide khổng lồ get this to work?
it returns thư điện tử only for sdk registered user and return null for all users even if i login using email.$response = $fb->get("/me?fields=id,name,first_name,last_name,email,gender,education,birthday,location,picture,link", $accessToken);
but it returns null except my registered account.
Error in PHP 8.1 FacebookFacebookApp implements the Serializable interface, which is deprecated. Implement __serialize() & __unserialize() instead (or in addition, if tư vấn for old PHP versions is necessary)
Hi All.
I"m calling $helper->getLogoutUrl($access_token, $redirectUrl); & it doesn"t log me out of facebook. I know it"s a valid token và the redirect actually works, but my user stays logged-in to lớn facebook no matter what.
Is there something specific beyond the redirect that I need lớn do? I need to log my user out of facebook so that they can switch to a different facebook user before using my application. I vì chưng not use facebook to lớn authenticate in my app.
TIA
I have an phầm mềm that"s pulling business page data (star reviews) working on a testing app, but as soon as I switch khổng lồ a live tiện ích it no longer works.
Can someone confirm this is working.
Dear all.I want to lớn post a video on my Facebook page with the name of the page.What is the correct permeation that I need lớn have on my app?
Reagrads
FACEBOOK TOOLKIT a tool khổng lồ get Facebook data, and some Facebook bots, & extra tools found on Facebook Toolkit ++. Graph API Facebook. Made with ❤️ b
LINE Login for PHP SDK of the LINE Login API for PHP Documentation See the official API documentation for more information. Installation Use the packa
Archival Notice: This SDK is archived. You can continue to use it, but no new features or tư vấn requests will be accepted. For the new version, refe
Facebook Business SDK for PHP Introduction The Facebook Business SDK is a one-stop cửa hàng to help our partners better serve their businesses. Partners a
Shopware PHP SDK is a simple SDK implementation of Shopware 6 APIs. It helps lớn access the API in an object-oriented way.
1Password Connect PHP SDK The 1Password Connect PHP SDK provides your PHP applications access lớn the 1Password Connect API hosted on your infrastructu
Laravel Facebook SDK A fully unit-tested package for easily integrating the Facebook SDK v5 into Laravel and Lumen 5.0, 5.1, 5.2, và 5.3. This is packa
Sobre Beedoo SDK Acessar documentação completa da Beedoo API. A API é organizada seguindo a arquitetura REST, boas práticas, convenções e padrões como
OpenAI GPT-3 Api Client in PHP Installation You can install the package via composer: composer require orhanerday/open-ai Usage use OrhanerdayOpenAi
PHP SDK for the Sellix Developers API (developers.sellix.io). Quickly get started and create products, payments & more using PHP.
Mark Sign - Gateway API PHP SDK
ExchangeRatesAPI - Currency Exchange Rates API SDK This is an unofficial wrapper for the awesome, miễn phí ExchangeRatesAPI, which provides exchange rate
PHP API TO-DO-LIST v.2.0 This API aims lớn present a brief to lớn consume a API resources, mainly for students in the early years of Computer Science cours
The NKN open API is a blockchain-to-database parser with an easy khổng lồ use interface written in PHP. We're using Laravel as our framework khổng lồ provide a clean và maintainable code.
AWS Service Provider for Laravel 5/6/7/8 This is a simple Laravel service provider for making it easy lớn include the official AWS SDK for PHP in your
Firebase Admin PHP SDK Table of Contents Overview Installation Documentation support License Overview Firebase provides the tools and infrastructure y
Notion PHP SDK This is an unofficial PHP SDK for the new public Notion API. It's work in progress as we didn't get the change lớn be included lớn the pr
afdian-php-sdk 爱发电非官方简易 PHP SDK by Akkariin 这是一个简单的 SDK,可以用于查询爱发电的订单和赞助者信息 Installation 将项目 clone 到本地即可 git clone https://github.com/ZeroDream-CN/afdi
Laravel Package to manage Web & API authentication with AWS Cognito AWS Cognito package using the AWS SDK for PHP This package provides a simple way