0

我想在我的网站上显示一个帐户的推文。问题是推文总是以 format 出现http://t.co/...,而​​不是我想要的完整链接。

例如,我获得:

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...

我希望这些推文看起来像这样:

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...

为了使我的应用程序,我遵循了以下说明:

使用 Twitter API 版本 1.1 检索 user_timeline 的最简单 PHP 示例(从这里我们可以获取每条推文的文本,链接格式为http://t.co/...:)

使用 Get Statuses API 1.1 时在推文中呈现链接(此链接中得分最高的答案的代码替换了,例如,"http://t.co/Nf7j4TaB"带有超链接的文本"<a target='_blank' href='http://t.co/Nf7j4TaB'>http://t.co/Nf7j4TaB</a>"

我非常感谢有关如何呈现 twitter 链接的任何帮助!

4

3 回答 3

0

通过您遵循的教程,您可以使用这些属性来显示实际链接。

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

于 2013-06-14T13:26:58.233 回答
0

目前唯一的 JavaScript 解决方案可以在不使用新的 1.1 API 的情况下在您的网站上获取 Twitter 帖子,并且实际上返回帖子中的完整 url,而不是 twitter 缩短版本:-) http://goo.gl/JinwJ

于 2013-06-14T15:55:16.407 回答
0

谢谢您的回答。

在分析了建议链接(https://dev.twitter.com/docs/tweet-entities)中的 JSON 后,我针对暴露的问题编写了一个解决方案:

// ...
$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.
}
于 2013-06-14T18:38:53.563 回答