0

I am trying to get tweets from Twitter with text body, like in Twitter widget, using search API v1.1. What is the problem. This is my code:

$connection = new TwitterOAuth($consumer_key, $consumer_secret, $twitter_access_token['oauth_token'], $twitter_access_token['oauth_token_secret']);
$tweets = $connection->get('search/tweets', ['count' => 30, 'result_type' => 'mixed', 'q' => $hashtags]);
return $tweets;

Each tweet has property "text", which contains something like this: tweet object

Here also can be images, quotes, etc. All of this is just text. Whithout html tags. But if I use widget, it returns something like this: tweet structure in widget

As you can see, quotes, hashtags, images and other stuff are wrapped in html tags and are displayed not like just text.

How can I get tweets with such text (with html tags), using search API v1.1? Thanks for any help.

Valentin Lorentz
  • 9,556
  • 6
  • 47
  • 69
  • I would be surprised if Twitter provided tweet data already formatted in this way. APIs are generally used to get _data_. Then you can format it however you want. – ChrisGPT was on strike Aug 21 '16 at 13:49
  • @Chris But, I think, there should be the solution, how I can achieve my goal. I am sure, I am not the only one, who want to show tweets in nice way, not just boring text. – Sergey Shambal Aug 21 '16 at 19:40
  • 1
    Sergey, nothing is preventing you from showing tweets "in a nice way". But the API doesn't return tweet data already formatted. It gives you the _raw data_ so you can format it yourself. – ChrisGPT was on strike Aug 21 '16 at 19:43
  • I've tried to write my own parser (with own bugs), but then I found this library, which helped me a lot: [TwitterTextFormatter](http://blog.netgloo.com/2015/08/16/php-getting-latest-tweets-and-displaying-them-in-html/) – Sergey Shambal Aug 25 '16 at 20:10

0 Answers0