|
2 | 2 |
|
3 | 3 | namespace Embed\Providers\OEmbed; |
4 | 4 |
|
| 5 | +use Embed\Adapters\Adapter; |
| 6 | +use Embed\Http\Response; |
5 | 7 | use Embed\Http\Url; |
6 | 8 |
|
7 | 9 | class Facebook extends EndPoint implements EndPointInterface |
8 | 10 | { |
9 | 11 | 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 | + } |
10 | 46 |
|
11 | 47 | /** |
12 | 48 | * {@inheritdoc} |
13 | 49 | */ |
14 | 50 | public function getEndPoint() |
15 | 51 | { |
16 | 52 | 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'); |
18 | 54 | } 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'); |
20 | 56 | } |
21 | 57 |
|
22 | 58 | return $endPoint->withQueryParameters([ |
23 | 59 | 'url' => (string) $this->getUrl(), |
24 | 60 | 'format' => 'json', |
| 61 | + 'access_token' => $this->key, |
25 | 62 | ]); |
26 | 63 | } |
27 | 64 | } |
0 commit comments