繁体   English   中英

Twitter feed和个人资料照片

[英]Twitter feed with profile photo

大家好,我需要一些帮助。 由于我不太擅长PHP,因此无法合并两个可以单独工作的函数。 我发现这个准备好的脚本可以在页面上显示多个Twitter提要。

<?php

// Pull from which accounts? Separated by a space, for example: Username Username Username 
$usernames = "Username Username Username"; 
// Number of tweets to pull in, total. 
$limit = "5"; 
// Show username? 0 = No, 1 = Yes. 
$show = 1;

// REMEBER: When using HTML, escape double-quotations like this: \"

// This comes before the entire block of tweets. 
$prefix = ""; 
// This comes before each tweet on the feed. 
$prefix_sub = ""; 
// This comes after the username but before the tweet content. 
$wedge = ""; 
// This comes after each tweet on the feed. 
$suffix_sub = ""; 
// This comes after the entire block of tweets. 
$suffix = "";

// It is recommended that you do not modify below this point without PHP knowledge.

function parse_feed($usernames, $limit, $show, $prefix_sub, $wedge, $suffix_sub) {

$usernames = str_replace(" ", "+OR+from%3A", $usernames); 
$feed = "http://search.twitter.com/search.atom?q=from%3A" . $usernames . "&rpp=" . $limit; 
$feed = file_get_contents($feed); 
$feed = str_replace("&", "&", $feed); 
$feed = str_replace("<", "<", $feed); 
$feed = str_replace(">", ">", $feed); 
$clean = explode("<entry>", $feed); 
$amount = count($clean) - 1;

for ($i = 1; $i <= $amount; $i++) {

$entry_close = explode("</entry>", $clean[$i]); 
$clean_content_1 = explode("<content type=\"html\">", $entry_close[0]); 
$clean_content = explode("</content>", $clean_content_1[1]); 
$clean_name_2 = explode("<name>", $entry_close[0]); 
$clean_name_1 = explode("(", $clean_name_2[1]); 
$clean_name = explode(")</name>", $clean_name_1[1]); 
$clean_uri_1 = explode("<uri>", $entry_close[0]); 
$clean_uri = explode("</uri>", $clean_uri_1[1]);

echo $prefix_sub; 
if ($show == 1) { echo "<a href=\"" . $clean_uri[0] . "\">" . $clean_name[0] . "</a>" . $wedge; } 
echo $clean_content[0]; 
echo $suffix_sub;

}

}

echo $prefix; 
parse_feed($usernames, $limit, $show, $prefix_sub, $wedge, $suffix_sub); 
echo $suffix;

// WRITTEN BY RYAN BARR (SPOOKY)! SPOOKYISMY.NAME

?>

为了添加个人资料照片,我创建了自己的功能,该功能非常简单:

<?php

function display_photo($username, $size='') 
{
    $image_code = 'http://api.twitter.com/1/users/profile_image/'. $username;
    return $image_code;

}
<?

但是我不能将这两个功能结合在一起,所以我将用户名和Twitter提要全部在一起://能帮我吗? 提前致谢!!

要在第一个功能中获取个人资料照片:

行之间: $clean_uri = explode("</uri>", $clean_uri_1[1]); echo $prefix_sub; 输入以下代码:

$profile_image_url_1 = explode('<link type="image/png" href="', $entry_close[0]); 
$profile_image_url = explode('" rel="image"/>', $profile_image_url_1[1]);
$profile_image_url = $profile_image_url[0];

echo $profile_image_url;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM