PHP code example of janwebdev / symfony-social-video-bundle
1. Go to this page and download the library: Download janwebdev/symfony-social-video-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
janwebdev / symfony-social-video-bundle example snippets
use Janwebdev\SocialVideoBundle\Message\VideoMessageBuilder;
use Janwebdev\SocialVideoBundle\Publisher\VideoPublisher;
class YourService
{
public function __construct(private VideoPublisher $publisher) {}
public function postVideo(): void
{
$message = VideoMessageBuilder::create()
->setVideoPath('/path/to/reel.mp4') // local file
// OR: ->setVideoUrl('https://cdn.example.com/reel.mp4')
->setTitle('My Amazing Short #Shorts')
->setDescription('Check this out!')
->addHashtag('reels')
->addHashtag('fyp')
->setPrivacy('public')
->forNetworks(['youtube', 'instagram', 'tiktok'])
->build();
$results = $this->publisher->publish($message);
foreach ($results as $result) {
if ($result->isSuccess()) {
echo "{$result->getProviderName()}: {$result->getPostUrl()}\n";
} else {
echo "Failed: {$result->getErrorMessage()}\n";
}
}
}
}
// Dispatch to message queue
$this->publisher->publishAsync($message);
$results = $this->publisher->publish($message);
if ($results->isAllSuccessful()) {
echo "Posted to all networks!\n";
}
$ytResult = $results->getResult('youtube');
if ($ytResult?->isSuccess()) {
echo "YouTube URL: " . $ytResult->getPostUrl() . "\n";
}
foreach ($results->getFailed() as $result) {
echo "Failed on {$result->getProviderName()}: {$result->getErrorMessage()}\n";
}
use Janwebdev\SocialVideoBundle\Publisher\Event\AfterPublishEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class VideoPostSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [AfterPublishEvent::class => 'onAfterPublish'];
}
public function onAfterPublish(AfterPublishEvent $event): void
{
foreach ($event->results->getSuccessful() as $result) {
// Log to database, send notifications, etc.
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.