Skip to content

Commit

Permalink
Merge pull request #398 from FlorisDerks/v3.x
Browse files Browse the repository at this point in the history
Fix Instagram/Facebook oEmbed calls (v3.x)
  • Loading branch information
oscarotero committed Oct 27, 2020
2 parents f19655f + 231603b commit 43da4eb
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 3 deletions.
41 changes: 39 additions & 2 deletions src/Providers/OEmbed/Facebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,63 @@

namespace Embed\Providers\OEmbed;

use Embed\Adapters\Adapter;
use Embed\Http\Response;
use Embed\Http\Url;

class Facebook extends EndPoint implements EndPointInterface
{
protected static $pattern = 'www.facebook.com/*';
protected $key;

/**
* {@inheritdoc}
*/
public static function create(Adapter $adapter)
{
$key = $adapter->getConfig('facebook[key]');

if (!empty($key)) {
$response = $adapter->getResponse();

if ($response->getUrl()->match(static::$pattern)) {
return new static($response, null, $key);
}

if ($response->getStartingUrl()->match(static::$pattern)) {
return new static($response, $response->getStartingUrl(), $key);
}
}
}

/**
* {@inheritdoc}
*/
protected function __construct(Response $response, $url = null, $key = null)
{
$this->response = $response;
$this->key = $key;

if ($url) {
$this->url = $url;
}
}

/**
* {@inheritdoc}
*/
public function getEndPoint()
{
if ($this->getUrl()->match(['*/videos/*', '/video.php'])) {
$endPoint = Url::create('https://www.facebook.com/plugins/video/oembed.json');
$endPoint = Url::create('https://graph.facebook.com/v8.0/oembed_video');
} else {
$endPoint = Url::create('https://www.facebook.com/plugins/post/oembed.json');
$endPoint = Url::create('https://graph.facebook.com/v8.0/oembed_post');
}

return $endPoint->withQueryParameters([
'url' => (string) $this->getUrl(),
'format' => 'json',
'access_token' => $this->key,
]);
}
}
39 changes: 38 additions & 1 deletion src/Providers/OEmbed/Instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Embed\Providers\OEmbed;

use Embed\Adapters\Adapter;
use Embed\Http\Response;
use Embed\Http\Url;

class Instagram extends EndPoint implements EndPointInterface
Expand All @@ -11,7 +13,41 @@ class Instagram extends EndPoint implements EndPointInterface
'www.instagram.com/p/*',
'instagr.am/p/*',
];
protected static $endPoint = 'https://api.instagram.com/oembed';
protected static $endPoint = 'https://graph.facebook.com/v8.0/instagram_oembed';
protected $key;

/**
* {@inheritdoc}
*/
public static function create(Adapter $adapter)
{
$key = $adapter->getConfig('facebook[key]');

if (!empty($key)) {
$response = $adapter->getResponse();

if ($response->getUrl()->match(static::$pattern)) {
return new static($response, null, $key);
}

if ($response->getStartingUrl()->match(static::$pattern)) {
return new static($response, $response->getStartingUrl(), $key);
}
}
}

/**
* {@inheritdoc}
*/
protected function __construct(Response $response, $url = null, $key = null)
{
$this->response = $response;
$this->key = $key;

if ($url) {
$this->url = $url;
}
}

/**
* {@inheritdoc}
Expand All @@ -24,6 +60,7 @@ public function getEndPoint()
->withQueryParameters([
'url' => (string) $url,
'format' => 'json',
'access_token' => $this->key,
]);
}
}

0 comments on commit 43da4eb

Please sign in to comment.