Skip to content

Commit

Permalink
Fixed Twitter sometimes returning empty data displayed somehow withou…
Browse files Browse the repository at this point in the history
…t errors.
  • Loading branch information
AmauryCarrade committed Apr 21, 2019
1 parent 042a160 commit 6e59859
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions shortcodes/TwitterShortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ private function processTweet($tweet_data, $is_quoted_tweet = false)

$tweet_html = Tweet::make(
$tweet_data['full_text'],
$tweet_data['entities']['urls'],
$tweet_data['entities']['user_mentions'],
$tweet_data['entities']['hashtags']
isset($tweet_data['entities']['urls']) && $tweet_data['entities']['urls'] != null ? $tweet_data['entities']['urls'] : [],
isset($tweet_data['entities']['user_mentions']) && $tweet_data['entities']['user_mentions'] != null ? $tweet_data['entities']['user_mentions'] : [],
isset($tweet_data['entities']['hashtags']) && $tweet_data['entities']['hashtags'] != null ? $tweet_data['entities']['hashtags'] : []
)->linkify();

// We want to be able to stylise the @ & #.
Expand Down Expand Up @@ -186,7 +186,7 @@ private function buildBaseInfo($method, $endpoint, $params)
$r = [];
ksort($params);

foreach($params as $key=>$value)
foreach($params as $key => $value)
{
$r[] = "$key=" . rawurlencode($value);
}
Expand Down Expand Up @@ -264,6 +264,15 @@ private function callTwitter($url)

curl_close($ch);

return json_decode($json, true);
$data = json_decode($json, true);

if (!$data)
{
return ['errors' => [['code' => 1, 'message' => 'Twitter returned an empty response.']]];
}
else
{
return $data;
}
}
}

0 comments on commit 6e59859

Please sign in to comment.