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

Facebook\Helper\CanvasHelper

The FacebookCanvasHelper is used to obtain an access token or signed request when working within the context of an app canvas.

Facebook\Helper\CanvasHelper( Facebook\Application $application )

Usage

If your app is loaded through Canvas, Facebook sends a POST request to your app with a signed request. This helper will handle validating and decrypting the signed request.

$fb = new Facebook\Facebook([/* */]);
$canvasHelper = $fb->getCanvasHelper();
$signedRequest = $canvasHelper->getSignedRequest();

if ($signedRequest) {
  $payload = $signedRequest->getPayload();
  var_dump($payload);
}

If a user has already authenticated your app, you can also obtain an access token.

$fb = new Facebook\Facebook([/* */]);
$canvasHelper = $fb->getCanvasHelper();

try {
  $accessToken = $canvasHelper->getAccessToken();
} catch(Facebook\Exception\ResponseException $e) {
  // When Graph returns an error
  echo 'Graph returned an error: ' . $e->getMessage();
} catch(Facebook\Exception\SDKException $e) {
  // When validation fails or other local issues
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
}

if (isset($accessToken)) {
  // Logged in.
}

The $accessToken will be null if the signed request did not contain any OAuth 2.0 data to obtain the access token.

Instance Methods

__construct()

public FacebookCanvasHelper __construct(Application $app, FacebookClient $client, $graphVersion = null)

Upon instantiation, FacebookCanvasHelper validates and decrypts the signed request that was sent via POST if present.

getAccessToken()

public Facebook\AccessToken|null getAccessToken()

Checks the signed request for authentication data and tries to obtain an access token access token.

getUserId()

public string|null getUserId()

A convenience method for obtaining a user's ID from the signed request if present. This will only return the user's ID if a valid signed request can be obtained and decrypted and the user has already authorized the app.

$userId = $canvasHelper->getUserId();

if ($userId) {
  // User is logged in
}

This is equivalent to accessing the user ID from the signed request entity.

$signedRequest = $canvasHelper->getSignedRequest();

if ($signedRequest) {
  $userId = $signedRequest->getUserId();
  // OR
  $userId = $signedRequest->get('user_id');
}

getAppData()

public string|null getAppData()

Gets the value that is set in the app_data property if present.

getSignedRequest()

public Facebook\SignedRequest|null getSignedRequest()

Returns the signed request as an instance of Facebook\SignedRequest if present.

getRawSignedRequest()

public string|null getRawSignedRequest()

Returns the raw encoded signed request as a string if present in the POST variables or null.

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