summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorcall-me-matt <nextcloud@matthiasheinisch.de>2021-02-22 22:57:10 +0100
committercall-me-matt <nextcloud@matthiasheinisch.de>2021-02-23 00:04:09 +0100
commit0c17c242364b93104f21d3cbbd9d9933f5910f9b (patch)
treeb9828c34d734ebb7a6876c557bd40d8b9041a28f /lib
parentea5e5ff3324c0ea19b257706e1572472687ef64a (diff)
add user agent
Signed-off-by: call-me-matt <nextcloud@matthiasheinisch.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/Service/Social/InstagramProvider.php25
1 files changed, 22 insertions, 3 deletions
diff --git a/lib/Service/Social/InstagramProvider.php b/lib/Service/Social/InstagramProvider.php
index a43d12c3..a930aaa7 100644
--- a/lib/Service/Social/InstagramProvider.php
+++ b/lib/Service/Social/InstagramProvider.php
@@ -23,18 +23,28 @@
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 InstagramProvider implements ISocialProvider {
/** @var IClientService */
private $httpClient;
+ /** @var LoggerInterface */
+ private $logger;
+
/** @var string */
public $name = "instagram";
- public function __construct(IClientService $httpClient) {
+ public function __construct(IClientService $httpClient,
+ LoggerInterface $logger) {
$this->httpClient = $httpClient->NewClient();
+ $this->logger = $logger;
}
/**
@@ -126,7 +136,12 @@ class InstagramProvider implements ISocialProvider {
*/
protected function getFromJson(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 insta displays the full static html page
+ 'User-Agent' => 'Googlebot/2.1'
+ ]
+ ]);
$jsonResult = json_decode($result->getBody(),true);
$location = explode('->' , $desired);
@@ -137,7 +152,11 @@ class InstagramProvider implements ISocialProvider {
$jsonResult = $jsonResult[$loc];
}
return $jsonResult;
- } catch (\Exception $e) {
+ } catch (RequestException $e) {
+ $this->logger->debug('Error fetching instagram urls', [
+ 'app' => Application::APP_ID,
+ 'exception' => $e
+ ]);
return null;
}
}