summaryrefslogtreecommitdiffstats
path: root/lib/Service
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2021-01-11 12:31:16 +0100
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2021-01-11 12:35:25 +0100
commitbf48bcd0669593a510fceca39d3bbda3c1c01ce5 (patch)
tree20c6c9d3ae56a4345a6fafbc3bd5026504c94194 /lib/Service
parent7646cbf0d2b66e8a0c5bff74ddd5813045b85b84 (diff)
Make sure twitter returns the raw static html page so we can get the profile picture properly
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'lib/Service')
-rw-r--r--lib/Service/Social/TwitterProvider.php25
-rw-r--r--lib/Service/SocialApiService.php21
2 files changed, 33 insertions, 13 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;
}
}
diff --git a/lib/Service/SocialApiService.php b/lib/Service/SocialApiService.php
index b1657734..2ea2f45b 100644
--- a/lib/Service/SocialApiService.php
+++ b/lib/Service/SocialApiService.php
@@ -23,22 +23,22 @@
namespace OCA\Contacts\Service;
-use OCA\Contacts\Service\Social\CompositeSocialProvider;
use OCA\Contacts\AppInfo\Application;
+use OCA\Contacts\Service\Social\CompositeSocialProvider;
-use OCP\Contacts\IManager;
-use OCP\IAddressBook;
+use OCA\DAV\CardDAV\CardDavBackend;
+use OCA\DAV\CardDAV\ContactsManager;
-use OCP\Util;
-use OCP\IConfig;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Contacts\IManager;
use OCP\Http\Client\IClientService;
-use OCA\DAV\CardDAV\CardDavBackend;
-use OCA\DAV\CardDAV\ContactsManager;
-use OCP\IURLGenerator;
+use OCP\IAddressBook;
+use OCP\IConfig;
use OCP\IL10N;
-use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\IURLGenerator;
+use OCP\Util;
class SocialApiService {
private $appName;
@@ -175,7 +175,7 @@ class SocialApiService {
try {
// get corresponding addressbook
- $addressBook = $this->getAddressBook($addressbookId);
+ $addressBook = $this->getAddressBook(urldecode($addressbookId));
if (is_null($addressBook)) {
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
}
@@ -216,6 +216,7 @@ class SocialApiService {
break;
}
} catch (\Exception $e) {
+ return $e;
}
}