Skip to content

Commit 43da4eb

Browse files
authored
Merge pull request #398 from FlorisDerks/v3.x
Fix Instagram/Facebook oEmbed calls (v3.x)
2 parents f19655f + 231603b commit 43da4eb

File tree

2 files changed

+77
-3
lines changed

2 files changed

+77
-3
lines changed

src/Providers/OEmbed/Facebook.php

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,63 @@
22

33
namespace Embed\Providers\OEmbed;
44

5+
use Embed\Adapters\Adapter;
6+
use Embed\Http\Response;
57
use Embed\Http\Url;
68

79
class Facebook extends EndPoint implements EndPointInterface
810
{
911
protected static $pattern = 'www.facebook.com/*';
12+
protected $key;
13+
14+
/**
15+
* {@inheritdoc}
16+
*/
17+
public static function create(Adapter $adapter)
18+
{
19+
$key = $adapter->getConfig('facebook[key]');
20+
21+
if (!empty($key)) {
22+
$response = $adapter->getResponse();
23+
24+
if ($response->getUrl()->match(static::$pattern)) {
25+
return new static($response, null, $key);
26+
}
27+
28+
if ($response->getStartingUrl()->match(static::$pattern)) {
29+
return new static($response, $response->getStartingUrl(), $key);
30+
}
31+
}
32+
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*/
37+
protected function __construct(Response $response, $url = null, $key = null)
38+
{
39+
$this->response = $response;
40+
$this->key = $key;
41+
42+
if ($url) {
43+
$this->url = $url;
44+
}
45+
}
1046

1147
/**
1248
* {@inheritdoc}
1349
*/
1450
public function getEndPoint()
1551
{
1652
if ($this->getUrl()->match(['*/videos/*', '/video.php'])) {
17-
$endPoint = Url::create('https://www.facebook.com/plugins/video/oembed.json');
53+
$endPoint = Url::create('https://graph.facebook.com/v8.0/oembed_video');
1854
} else {
19-
$endPoint = Url::create('https://www.facebook.com/plugins/post/oembed.json');
55+
$endPoint = Url::create('https://graph.facebook.com/v8.0/oembed_post');
2056
}
2157

2258
return $endPoint->withQueryParameters([
2359
'url' => (string) $this->getUrl(),
2460
'format' => 'json',
61+
'access_token' => $this->key,
2562
]);
2663
}
2764
}

src/Providers/OEmbed/Instagram.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Embed\Providers\OEmbed;
44

5+
use Embed\Adapters\Adapter;
6+
use Embed\Http\Response;
57
use Embed\Http\Url;
68

79
class Instagram extends EndPoint implements EndPointInterface
@@ -11,7 +13,41 @@ class Instagram extends EndPoint implements EndPointInterface
1113
'www.instagram.com/p/*',
1214
'instagr.am/p/*',
1315
];
14-
protected static $endPoint = 'https://api.instagram.com/oembed';
16+
protected static $endPoint = 'https://graph.facebook.com/v8.0/instagram_oembed';
17+
protected $key;
18+
19+
/**
20+
* {@inheritdoc}
21+
*/
22+
public static function create(Adapter $adapter)
23+
{
24+
$key = $adapter->getConfig('facebook[key]');
25+
26+
if (!empty($key)) {
27+
$response = $adapter->getResponse();
28+
29+
if ($response->getUrl()->match(static::$pattern)) {
30+
return new static($response, null, $key);
31+
}
32+
33+
if ($response->getStartingUrl()->match(static::$pattern)) {
34+
return new static($response, $response->getStartingUrl(), $key);
35+
}
36+
}
37+
}
38+
39+
/**
40+
* {@inheritdoc}
41+
*/
42+
protected function __construct(Response $response, $url = null, $key = null)
43+
{
44+
$this->response = $response;
45+
$this->key = $key;
46+
47+
if ($url) {
48+
$this->url = $url;
49+
}
50+
}
1551

1652
/**
1753
* {@inheritdoc}
@@ -24,6 +60,7 @@ public function getEndPoint()
2460
->withQueryParameters([
2561
'url' => (string) $url,
2662
'format' => 'json',
63+
'access_token' => $this->key,
2764
]);
2865
}
2966
}

0 commit comments

Comments
 (0)