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

Video Uploading with the Facebook SDK for PHP

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

Facebook\FileUpload\Video(string $pathToVideoFile, int $maxLength = -1, int $offset = -1)

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

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

use Facebook\FileUpload\Video;

$myVideoFileToUpload = new FacebookVideo('/path/to/video-file.mp4');

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

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

$myVideoFileToUpload = $fb->videoToUpload('/path/to/video-file.mp4'),

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.

Warning: Uploading videos may cause a timeout. Make sure to configure your HTTP client to increase timeout time before uploading videos.

Usage

In Graph v2.3, functionality was added to upload video files in chunks. The PHP SDK provides a handy API to easily upload video files in chunks via the uploadVideo() method.

// Upload a video for a user (chunked)
$data = [
  'title' => 'My awesome video',
  'description' => 'More info about my awesome video.',
];

try {
  $response = $fb->uploadVideo('me', '/path/to/video.mp4', $data, '{user-access-token}');
} catch(Facebook\Exception\SDKException $e) {
  echo 'Error: ' . $e->getMessage();
  exit;
}

echo 'Video ID: ' . $response['video_id'];

For versions of Graph before v2.3, videos had to be uploaded in one request.

// Upload a video for a user
$data = [
  'title' => 'My awesome video',
  'description' => 'More info about my awesome video.',
  'source' => $fb->videoToUpload('/path/to/video.mp4'),
];

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

$graphNode = $response->getGraphNode();

echo 'Video ID: ' . $graphNode['id'];
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