Skip to content

Commit

Permalink
Fixed Instagram posts badly retrieved if Instagram redirects to anoth…
Browse files Browse the repository at this point in the history
…er URL.

(May happen if there is a missing trailing shash, for example.)
  • Loading branch information
AmauryCarrade committed Aug 14, 2018
1 parent b6db87d commit 065a56a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v1.1.2
## 14-08-2018

1. [](#bugfix)
* Fixed Instagram posts failing to be retrieved in some cases.

# v1.1.1
## 14-08-2018

Expand Down
2 changes: 1 addition & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Static Social Embeds
version: 1.1.1
version: 1.1.2
description: |
Embeds social status (like tweets, instagram posts, toots, etc.) in articles without using their embed iframe,
but rather statically without any dependency to the service.
Expand Down
6 changes: 5 additions & 1 deletion shortcodes/InstagramShortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,20 @@ protected function getData($url)
curl_setopt_array($ch, [
CURLOPT_TIMEOUT => 3600,
CURLOPT_URL => $url,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false
]);

$raw_instagram_html = curl_exec($ch);

$error_code = curl_errno($ch);
$error = $error_code != 0 ? (': #' . $error_code . ' - ' . curl_error($ch)) : '';

curl_close($ch);

if (!$raw_instagram_html)
return ['errors' => [['code' => 0, 'message' => 'Unable to retrieve instagram post']], 'url' => $url];
return ['errors' => [['code' => 0, 'message' => 'Unable to retrieve instagram post' . $error]], 'url' => $url];

preg_match('/window\._sharedData = (.*);<\/script>/', $raw_instagram_html, $matches, PREG_OFFSET_CAPTURE, 0);

Expand Down

0 comments on commit 065a56a

Please sign in to comment.