The Facebook Sdk For Php Provides A Native Interface To The Graph Api And Facebook Login

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

Installation

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


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 lớn make it work with Guzzle 6.x.

Upgrading to lớn v5.x

Upgrading from v4.x? Facebook PHP SDK v5.x introduced breaking changes. Please read the tăng cấp 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.


"app-id", "app_secret" => "app-secret", "default_graph_version" => "v2.10", //"default_access_token" => "access-token", // optional>);// Use one of the helper classes khổng lồ 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();">

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.

Tests

The 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.


Contributing

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

License

Please see the license tệp tin for more information.

Security Vulnerabilities

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

GitHub

https://github.com/facebookarchive/php-graph-sdk
1. Facebook SDK returned an error: Cross-site request forgery validation failed. Required param "state" missing.

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).

Advantages

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.

Future work

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::getHttpClient

The 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.

Setup

To 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

Via constructor

use FacebookEntitiesFacebookBatchRequest;use FacebookEntitiesFacebookRequest;// If $facebookApp và $accessToken on a `FacebookRequest` are null, it will fallback to the parent `FacebookBatchRequest` app và token.$requests = < new FacebookRequest(null, null, "GET", "/me"), new FacebookRequest($facebookApp, "access-token", "POST", "/me/feed", <"foo"=>"bar">), >;$batchRequest = new FacebookBatchRequest($facebookApp, "access-token", $requests);

Via add() as an array

use FacebookEntitiesFacebookRequest;// Numeric array:$requests = < new FacebookRequest(null, null, "GET", "/me"), new FacebookRequest($facebookApp, "access-token", "POST", "/me/feed", <"foo"=>"bar">), >;$batchRequest->add($requests);// ... OR ...// Associative array:// The key of the array will be used lớn assign a name to lớn the request.$requests = < "named-request-one" => new FacebookRequest(null, null, "GET", "/me"), "named-request-two" => new FacebookRequest($facebookApp, "access-token", "POST", "/me/feed", <"foo"=>"bar">), >;$batchRequest->add($requests);

Via add() as a FacebookRequest

$batchRequest->add(new FacebookRequest(null, null, "GET", "/me"));$batchRequest->add(new FacebookRequest($facebookApp, access-token, "GET", "/me"), "my-reqest-name");Getting a response from batch request$facebookBatchResponse = $facebookClient->sendBatchRequest($batchRequest);foreach ($facebookBatchResponse as $response) if (!$response->isError()) // $response is a `FacebookResponse` entity else $e = $response->getThrownException(); echo $e->getMessage(); HelpersYou also pass along the FacebookApp & FacebookClient into the helpers lượt thích so:

$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 FacebookHttpClientInterface

I also simplified the FacebookHttpClientInterface so that the request headers could be sent as an argument in the send() method.

Integration Tests Labled

The 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! :)

TODO

For the next few PR"s:

Factories lớn make FacebookRequest"s và FacebookBatchRequest"sCollections on GrahObjectAdding GraphList with pagination

Hey 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.


16. What is the alternative permeation for manage_pages và publishh_pages since they are deprecated

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


Related tags
APIphp-graph-sdk
a tool to get Facebook data, and some Facebook bots, and extra tools found on Facebook Toolkit ++.
*

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


SDK of the LINE Login API for PHP

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


Zoho CRM API SDK is a wrapper to lớn Zoho CRM APIs. By using this sdk, user can build the application with ease

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


An SDK built to facilitate application development for quảng cáo facebook API.

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
*

Shopware PHP SDK is a simple SDK implementation of Shopware 6 APIs. It helps lớn access the API in an object-oriented way.


The 1Password Connect PHP SDK provides your PHP applications access lớn the 1Password Connect API hosted on your infrastructure and leverage the power nguồn of 1Password Secrets Automation

1Password Connect PHP SDK The 1Password Connect PHP SDK provides your PHP applications access lớn the 1Password Connect API hosted on your infrastructu


Fully unit tested Facebook SDK v5 integration for Laravel và Lumen
*

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


Esse SDK em PHP foi desenvolvido no intuito de tornar mais prático a integração com nossa API.

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


A PHP SDK for accessing the OpenAI GPT-3 API
*

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)

PHP SDK for the Sellix Developers API (developers.sellix.io). Quickly get started and create products, payments & more using PHP.


Jan 18, 2022
Mark Sign - Gateway API PHP SDK

Mark Sign - Gateway API PHP SDK


Feb 22, 2022
ExchangeRatesAPI - Currency Exchange Rates API SDK

ExchangeRatesAPI - Currency Exchange Rates API SDK This is an unofficial wrapper for the awesome, miễn phí ExchangeRatesAPI, which provides exchange rate


This API provides functionality for creating và maintaining users khổng lồ control a simple To-Do-List application. The following shows the API structure for users và tasks resources.
*

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 lớn use interface written in PHP

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.


A Laravel 5+ (and 4) service provider for the AWS SDK for PHP

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


Unofficial Firebase Admin SDK for PHP

Firebase Admin PHP SDK Table of Contents Overview Installation Documentation support License Overview Firebase provides the tools and infrastructure y


Notion PHP SDK
*

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


爱发电非官方简易 PHP SDK

afdian-php-sdk 爱发电非官方简易 PHP SDK by Akkariin 这是一个简单的 SDK,可以用于查询爱发电的订单和赞助者信息 Installation 将项目 clone 到本地即可 git clone https://github.com/ZeroDream-CN/afdi


AWS Cognito package using the AWS SDK for PHP/Laravel
*

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