summaryrefslogtreecommitdiffstats
path: root/lib/Service/Social/TwitterProvider.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Service/Social/TwitterProvider.php')
-rw-r--r--lib/Service/Social/TwitterProvider.php25
1 files changed, 22 insertions, 3 deletions
diff --git a/lib/Service/Social/TwitterProvider.php b/lib/Service/Social/TwitterProvider.php
index 18cd0d46..9460fb40 100644
--- a/lib/Service/Social/TwitterProvider.php
+++ b/lib/Service/Social/TwitterProvider.php
@@ -23,17 +23,27 @@
namespace OCA\Contacts\Service\Social;
+use GuzzleHttp\Exception\RequestException;
+use GuzzleHttp\RequestOptions;
+use OC\AppFramework\Http\Request;
+use OCA\Contacts\AppInfo\Application;
use OCP\Http\Client\IClientService;
+use Psr\Log\LoggerInterface;
class TwitterProvider implements ISocialProvider {
/** @var IClientService */
private $httpClient;
+ /** @var LoggerInterface */
+ private $logger;
+
/** @var string */
public $name = "twitter";
- public function __construct(IClientService $httpClient) {
+ public function __construct(IClientService $httpClient,
+ LoggerInterface $logger) {
$this->httpClient = $httpClient->NewClient();
+ $this->logger = $logger;
}
/**
@@ -112,7 +122,12 @@ class TwitterProvider implements ISocialProvider {
*/
protected function getFromHtml(string $url, string $desired) : ?string {
try {
- $result = $this->httpClient->get($url);
+ $result = $this->httpClient->get($url, [
+ RequestOptions::HEADERS => [
+ // Make the request as google bot so twitter display the full static html page
+ 'User-Agent' => 'Googlebot/2.1'
+ ]
+ ]);
$htmlResult = new \DOMDocument();
$htmlResult->loadHTML($result->getBody());
@@ -127,7 +142,11 @@ class TwitterProvider implements ISocialProvider {
}
}
return null;
- } catch (\Exception $e) {
+ } catch (RequestException $e) {
+ $this->logger->debug('Error fetching twitter urls', [
+ 'app' => Application::APP_ID,
+ 'exception' => $e
+ ]);
return null;
}
}