diff --git a/src/Providers/OEmbed/Facebook.php b/src/Providers/OEmbed/Facebook.php index 6cc03ce6..2e4e0c4a 100644 --- a/src/Providers/OEmbed/Facebook.php +++ b/src/Providers/OEmbed/Facebook.php @@ -2,11 +2,47 @@ 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} @@ -14,14 +50,15 @@ class Facebook extends EndPoint implements EndPointInterface 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, ]); } } diff --git a/src/Providers/OEmbed/Instagram.php b/src/Providers/OEmbed/Instagram.php index 2ac552c8..8f7f8874 100644 --- a/src/Providers/OEmbed/Instagram.php +++ b/src/Providers/OEmbed/Instagram.php @@ -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 @@ -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} @@ -24,6 +60,7 @@ public function getEndPoint() ->withQueryParameters([ 'url' => (string) $url, 'format' => 'json', + 'access_token' => $this->key, ]); } }