I am creating a Twitter API but the API isn't returning the whole tweet, it seems to stop when their is a link in the tweet. I am using PHP with TwitterAPIExchange.php, how can I fix this?
Example:
Ingewikkelde antwoorden op vragen van @AgnesMulderCDA over de #waakvlam van de #NAM. De NAM hoeft pas in november t… https:// t.co/ZM0Tuk9AYv
Should be this: https://twitter.com/SGaster/status/849334531907887104
$connection = new TwitterOAuth($CONSUMER_KEY, $CONSUMER_SECRET, $access_token, $access_token_secret);
$content = $connection->get("account/verify_credentials");
$tweets = $connection->get('favorites/list',['count' => 50,'include_entities' => false,'screen_name' => $screen_name]);
if(isset($tweets))
{
displayTweets($tweets); /* To display follower's tweets (This function is in file functions.php) */
}
else
{
echo "<div>";
echo "Can't fetch Tweets of this user.Please Refresh this page or try again later.";
echo "</div>";
}
how can I extend the tweet?
edit; this is my displayTweets() file
<?php
/* This file contains one function 'displayTweets'*/
/* displayTweets() function is used to display Tweets in jQuery slider */
require 'lib/makeLinks.php';
function displayTweets($tweets)
{
$i = 0;
foreach ($tweets as $key)
{
if ($i<=200)
{
if (isset($key->user->profile_image_url_https))
{
$tweet_profile_url = $key->user->profile_image_url_https;
}
echo "<div class='tweetBox'>";
echo "<div class='media slides' style='height:370px;'>";
echo "<div class='media-left'>";
if (isset($tweet_profile_url))
{
echo "<img src='".$tweet_profile_url."' class='media-object' style='height:50px,width:50px;'/>";
}
echo "</div>";
echo "<div class='media-body'>";
if (isset($key->user->name))
{
echo "<b style='font-size: 25px;'>".$key->user->name."</b>";
}
/*if (isset($key->user->verified))
{
if ($key->user->verified == 1)echo "<img src='images/download.png' class='verified_twitter_img' style='height:15px;
width:15px;'/>";
}*/
if (isset($key->user->screen_name))
{
echo " @".$key->user->screen_name."♦"; //will display black diamond between screen_name of user and date of tweet
}
if (isset($key->created_at)) //date of tweet
{
$formatted_date = date_formate($key->created_at);
echo $formatted_date;
}
echo "<br/>";
if (isset($key->text))
{
$tweet_and_links makeLinks($key->text); //This function(lib/makeLinks.php file) is used to find links in tweet and place it in <a> tag
}
if (isset($tweet_and_links))
{
echo $tweet_and_links;
}
echo "<br/>";
if (isset($key->entities->media)) {
foreach ($key->entities->media as $media) {
echo "<img src='".$media->media_url_https.":small' style='height:280px;width:270px;'/>"; //':small' is written for size, Twitter API provides four sizes - thumb,small,medium and large
}
}
echo "<br/>";
echo "</div>";
echo "</div>";
echo "</div>";
$i++;
} else
{
break;
}
}
}
function date_formate($dt) {
//convert date from +0000 timezone to +0530 timezone
$date = new DateTime($dt);
$date->setTimezone(new DateTimeZone('Asia/Muscat')); //Srilanka time zone is used because Indian time zone is not provided by twitter
$changed_date = $date->format('H:i, M d y');
return $changed_date;
}
This is because Tweets were originally 140 characters. So the text
field of the API response is limited to 140 character. If it is longer, you will see ... https:// t.co/...
You need to look at the extended_tweet
. So, in your PHP function displayTweets()
you need something like:
if ($tweet["truncated"] == true) {
return $tweet["extended_tweet"]["full_text"];
}
There's a helpful guide on the official documentation .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.