0

I want to display the tweets of an account in my website. The problem is that the tweets appear always with the format http://t.co/..., instead of the full link as desired by me.

For instance, I obtain:

the rules of the game are all implemented - local players can play together in this link: http://t.co/Nf7j4TaB

if you are very curious... then, here is the link to the xodul's section under development: http://t.co/6Zbti36T

etc...

and I want that these tweets appear like this:

the rules of the game are all implemented - local players can play together in this link: http://xodul.com/tests/js/

if you are very curious... then, here is the link to the xodul's section under development: http://xodul.com/tests 

etc...

To make my application I've followed the instructions from:

Simplest PHP example for retrieving user_timeline with Twitter API version 1.1 (from here we can get the text of each tweet, with the links coming in the format: http://t.co/...)

Rendering links in tweet when using Get Statuses API 1.1 (the code of the highest scored answer, in this link replaces, for instance, the text "http://t.co/Nf7j4TaB" with the hyperlink "<a target='_blank' href='http://t.co/Nf7j4TaB'>http://t.co/Nf7j4TaB</a>")

I appreciate very much any help on how to render the twitter's links!

Community
  • 1
  • 1
sissi_luaty
  • 2,839
  • 21
  • 28
  • The code of the non-accepted answer is much easier to use ;) Regardless, maybe [this link](https://dev.twitter.com/docs/tweet-entities) can help. It's about tweet entities. – Jimbo Jun 14 '13 at 13:12
  • OK, maybe, I've just followed Rivers' answer (the accepted one at june 14th) because it's shorter than the other, which is now the accepted one... – sissi_luaty Sep 14 '13 at 19:40
  • That's because accepted one explains how to make the application and get your keys. If you use River's example, you can't @ tweet people correctly and there are loads of other issues that have been fixed. Feel free to use that if you like. The shortest solution isn't always the best. Lazy! :p – Jimbo Sep 15 '13 at 11:03
  • @jimbo I've removed the reference to the particular answer of the other page, so anyone can choose which answer wants to follow. I've only followed and then cited a code that worked for my case, and I didn't noticed the other code. I don't see why my messages have deserved -1, I'm not lazy. – sissi_luaty Sep 15 '13 at 11:59
  • Not my -1, but the latest accepted answer is most likely to be the most useful / correct :-) – Jimbo Sep 15 '13 at 15:17

3 Answers3

0

With the tutorial you followed you can use these attributes to show actual link.

Note: In API v1.1, entities will always be included unless you set include_entities to False or 0.

The urls entity

An array of URLs extracted from the Tweet text. Each URL entity comes with the following attributes:

url:    The URL that was extracted
display_url:    (only for t.co links) Not a URL but a string to display instead of the URL
expanded_url:   (only for t.co links) The fully resolved URL
indices:    The character positions the URL was extracted from

https://dev.twitter.com/docs/tweet-entities

wakqasahmed
  • 2,059
  • 1
  • 18
  • 23
0

JavaScript only solution for now to get Twitter posts on your site without using new 1.1 API and actually returns the full url in posts, not the twitter shortened version :-) http://goo.gl/JinwJ

Jason
  • 41
  • 1
0

Thank you for your answers.

After analyzing the JSON in the suggested link (https://dev.twitter.com/docs/tweet-entities), I wrote a solution to the exposed problem:

// ...
$twitter_data = json_decode($json);    // last line of the code in: http://stackoverflow.com/questions/12916539


// print the tweets, with the full URLs:
foreach ($twitter_data as $item) {
    $text = $item->text;

    foreach ($item->entities->urls as $url) {
        $text = str_replace($url->url, $url->expanded_url, $text);
    }
    echo $text . '<br /><br />';

    // optionally, here, the code from: http://stackoverflow.com/questions/15610968/
    // can be added, too.
}
sissi_luaty
  • 2,839
  • 21
  • 28