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

File Uploading with the Facebook SDK for PHP

Uploading files to the Graph API is made a breeze with the Facebook SDK for PHP.

Facebook\FileUpload\File(string $pathToFile, int $maxLength = -1, int $offset = -1)

The FacebookFile entity represents a local or remote file to be uploaded with a request to Graph.

There are two ways to instantiate a FacebookFile entity. One way is to instantiate it directly:

use Facebook\FileUpload\File;

$myFileToUpload = new FacebookFile('/path/to/file.jpg');

Alternatively, you can use the fileToUpload() factory on the Facebook\Facebook super service to instantiate a new FacebookFile entity.

$fb = new Facebook\Facebook(/* . . . */);

$myFileToUpload = $fb->fileToUpload('/path/to/file.jpg');

Partial file uploads are possible using the $maxLength and $offset parameters which provide the same functionality as the $maxlen and $offset parameters on the stream_get_contents() PHP function.

Usage

The following example uploads a photo for a user.

$data = [
  'message' => 'My awesome photo upload example.',
  'source' => $fb->fileToUpload('/path/to/photo.jpg'),
  // Or you can provide a remote file location
  //'source' => $fb->fileToUpload('https://example.com/photo.jpg'),
];

try {
  $response = $fb->post('/me/photos', $data);
} catch(Facebook\Exception\SDKException $e) {
  echo 'Error: ' . $e->getMessage();
  exit;
}

$graphNode = $response->getGraphNode();

echo 'Photo ID: ' . $graphNode['id'];

Note: Although you can use fileToUpload() to upload a remote file, it is more efficient to just point the Graph request to the the remote file with the url param.

// Upload a remote photo for a user without using the FacebookFile entity
$data = [
  'message' => 'A neat photo upload example. Neat.',
  'url' => 'https://example.com/photo.jpg',
];

$response = $fb->post('/me/photos', $data);
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky