Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Facebook Graph Sdk Laravel Package

martin1982/facebook-graph-sdk

PHP 7.4+ Facebook Graph SDK (v7) for accessing the Facebook Platform. Install via Composer, initialize with app ID/secret, and make Graph API requests with built-in helpers for login flows and access tokens. Includes docs and PHPUnit tests.

View on GitHub
Deep Wiki
Context7

FacebookRequest for the Facebook SDK for PHP

Represents a request that will be sent to the Graph API.

Facebook\Request

You can instantiate a new FacebookRequest entity directly by sending the arguments to the constructor.

use Facebook\Request;

$request = new FacebookRequest(  
  Facebook\Application $app,
  string $accessToken,
  string $method,
  string $endpoint,
  array $params,
  string $eTag,
  string $graphVersion
);

Alternatively, you can make use of the request() factory provided by Facebook\Facebook to create new FacebookRequest instances.

The FacebookRequest entity does not actually make any calls to the Graph API, but instead just represents a request that can be sent to the Graph API later. This is most useful for making batch requests using Facebook\Facebook::sendBatchRequest() or Facebook\Client::sendBatchRequest().

Usage:

$fbApp = new Facebook\Application('{app-id}', '{app-secret}');
$request = new Facebook\Request($fbApp, '{access-token}', 'GET', '/me');

// OR

$fb = new Facebook\Facebook(/* . . . */);
$request = $fb->request('GET', '/me');

// Send the request to Graph
try {
  $response = $fb->getClient()->sendRequest($request);
} catch(Facebook\Exception\ResponseException $e) {
  // When Graph returns an error
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exception\SDKException $e) {
  // When validation fails or other local issues
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}

$graphNode = $response->getGraphNode();

echo 'User name: ' . $graphNode['name'];

Instance Methods

setAccessToken()

public setAccessToken(string|Facebook\AccessToken $accessToken)

Sets the access token to be used for the request.

getAccessToken()

public string getAccessToken()

Returns the access token to be used for the request in the form of a string.

setApp()

public setApp(Facebook\Application $app)

Sets the Facebook\Application entity used with this request.

getApplication()

public Facebook\Application getApplication()

Returns the Facebook\Application entity used with this request.

getAppSecretProof()

public string getAppSecretProof()

Returns the app secret proof to sign the request.

setMethod()

public setMethod(string $method)

Sets the HTTP verb to use for the request.

getMethod()

public string setMethod()

Returns the HTTP verb to use for the request.

setEndpoint()

public setEndpoint(string $endpoint)

Sets the Graph URL endpoint to be used with the request. The endpoint must be excluding the host name and Graph version number prefix.

$request->setEndpoint('/me');

getEndpoint()

public string getEndpoint()

Returns the Graph URL endpoint to be used with the request.

setHeaders()

public setHeaders(array $headers)

Sets additional request headers to be use with the request. The supplied headers will be merged with the existing headers. The headers should be sent as an associative array with the key being the header name and the value being the header value.

$request->setHeaders([
  'X-foo-header' => 'Something',
]);

getHeaders()

public array getHeaders()

Returns the request headers that will be sent with the request. The eTag headers If-None-Match are appended automatically.

setETag()

public setETag(string $eTag)

Sets the eTag that will be using for matching the If-None-Match header.

setParams()

public setParams(array $params)

For GET requests, the array of params will be converted to a query string and appended to the URL.

$request->setParams([
  'foo' => 'bar',
  'limit' => 10,
]);
// /endpoint?foo=bar&limit=10

For POST requests, the array of params will be sent in the POST body encoded as application/x-www-form-urlencoded for most request. If the request includes a file upload the params will be encoded as multipart/form-data.

getParams()

public array getParams()

Returns an array of params to be sent with the request. The access_token and appsecret_proof params will be automatically appended to the array of params.

getGraphVersion()

public string getGraphVersion()

Returns the Graph version prefix to be used with the request.

getUrl()

public string getUrl()

Returns the endpoint of the Graph URL for the request. This will include the Graph version prefix but will not include the host name. The host name is determined after the request is sent to Facebook\Client.

$fb = new Facebook\Facebook(/* . . . */);
$request = $fb->request('GET', '/me', ['fields' => 'id,name']);

$url = $request->getUrl();
// /v10.0/me?fields=id,name&access_token=token&appsecret_proof=proof
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
craftcms/url-validator
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony