PHP code example of samayamx / embed-extractor

1. Go to this page and download the library: Download samayamx/embed-extractor 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/ */

    

samayamx / embed-extractor example snippets


use Samaya\Embed\Extract;

$extractor = new Extract(
    'User-Agent-Cool',
    '1234567890123456',
    '0123456789abcdef0123456789abcdef'
);

Route::get('/embed', function (Request $request) use ($extractor) {
    $url = $request->get('url');
    try {
        $image = $extractor->getImage($url);
        $html = $extractor->getHtml($url);

        return response()->json(compact('url', 'html', 'image'));
    } catch (\DomainException $domainException) {
        // for Facebook "OpenGraph" errors
        return response()->json(
          ['message' => $domainException->getMessage()],
          $domainException->getCode()
        );
    } catch (\Exception $exception) {
        // handle other exceptions as well
        return response(
          $exception->getMessage(),
          $exception->getCode()
        );
    }
});

use Samaya\Embed\Extract;

// injected into the action handler:
Route::get('/embed', function (Extract $extractor, Request $request) {
    // ...
});

use Samaya\Embed\OEmbedExtract;

// using the facade
$image = OEmbedExtract::getImage($url);
$html = OEmbedExtract::getHtml($url);