-
-
Notifications
You must be signed in to change notification settings - Fork 308
/
Api.php
34 lines (24 loc) · 888 Bytes
/
Api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
declare(strict_types = 1);
namespace Embed\Adapters\Twitter;
use function Embed\getDirectory;
use Embed\HttpApiTrait;
class Api
{
use HttpApiTrait;
protected function fetchData(): array
{
$token = $this->extractor->getSetting('twitter:token');
if (!$token) {
return [];
}
$uri = $this->extractor->getUri();
$id = getDirectory($uri->getPath(), 2);
if (empty($id)) {
return [];
}
$this->extractor->getCrawler()->addDefaultHeaders(array('Authorization' => "Bearer $token"));
$this->endpoint = $this->extractor->getCrawler()->createUri("https://api.twitter.com/2/tweets/{$id}?expansions=author_id,attachments.media_keys&tweet.fields=created_at&media.fields=preview_image_url,url&user.fields=id,name");
return $this->fetchJSON($this->endpoint);
}
}