drgovyk64676 2012-02-19 11:34
浏览 70
已采纳

从XML文件显示Twitter个人资料图片

Currently I'm displaying tweets from a geocode along with the tweet itself along with the user name and the time and date it was tweeted. But now Im trying to access the profile picture which within the XML. I have already accessed the link to the status which is contained within a link tag.

This is the tag I'm trying to access.

<link type="image/png" href="http://a0.twimg.com/profile_images/1706928570/IMG00474-20111008-1737_normal.jpg" rel="image" >

The location within the XML file is line 18.

<feed xmlns:google="http://base.google.com/ns/1.0" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns="http://www.w3.org/2005/Atom" xmlns:twitter="http://api.twitter.com/" xmlns:georss="http://www.georss.org/georss" xml:lang="en-US" >
   <id>tag:search.twitter.com,2005:search/</id>
   <link type="text/html" href="http://search.twitter.com/search?q=" rel="alternate" >
   <link type="application/atom+xml" href="http://search.twitter.com/search.atom?q=" rel="self" >
   <title>- Twitter Search</title>
   <link type="application/opensearchdescription+xml" href="http://twitter.com/opensearch.xml" rel="search" >

   <link type="application/atom+xml" href="http://search.twitter.com/search.atom?since_id=170944502142476289&q=&geocode=51.5069999695%2C-0.142489999533%2C10.0mi%22london%22" rel="refresh" >
   <updated>2012-02-18T18:55:19Z</updated>
   <openSearch:itemsPerPage>15</openSearch:itemsPerPage>
   <link type="application/atom+xml" href="http://search.twitter.com/search.atom?page=2&max_id=170944502142476289&q=&geocode=51.5069999695%2C-0.142489999533%2C10.0mi%22london%22" rel="next" >
   <entry>
          <id>tag:search.twitter.com,2005:170944502142476289</id>
          <published>2012-02-18T18:55:19Z</published>
          <link type="text/html" href="http://twitter.com/LondITjobs/statuses/170944502142476289" rel="alternate" >
          <title>Software Development Engineer II - London #job #jobs #hiring #career http://t.co/VsxPdWdT</title>
          <content type="html" >Software Development Engineer II - London #job #jobs #hiring #career http://t.co/VsxPdWdT</content>
          <updated>2012-02-18T18:55:19Z</updated>
          <link type="image/png" href="http://a3.twimg.com/profile_images/1812202768/jr_100_normal.png" rel="image" >
          <twitter:geo>
          <google:location>London</google:location>
          <twitter:metadata>
                 <twitter:result_type>recent</twitter:result_type>
             </twitter:metadata>
          <twitter:source>twitterfeed</twitter:source>
          <twitter:lang>en</twitter:lang>
          <author>
                 <name>LondITjobs (ITjobsLondon)</name>
                 <uri>http://twitter.com/LondITjobs</uri>
             </author>
      </entry> 

Here is my code I currently have..

 <?php function get_twitter($feed) {

$xml = new SimpleXmlElement(file_get_contents($feed));


foreach ($xml->entry as $item) {

    $date = date("D, dS M Y g:i:sA T", strtotime($item->published));

    echo '<a href="' . $item->link->attributes()->href . '" target="_blank">' . $item->title . '</a><br />' .'<img src='.$item->link->link->attributes()->href .'/>'.'<br />'. $item->author->name . '<br />' . '<strong>' . $date . '</strong>' . '<br />';
}

}

?>

At the moment I have already accessed the first link tag with the entry section of the XML and Im a little unsure on how to access the picture. I thought about doing link[0] but don't know if this is the way to go. Any suggestions?

Heres what I currently have

  • 写回答

1条回答 默认 最新

  • douzhannao5357 2012-02-19 22:02
    关注

    Have finally worked out a solution.

    '<img src="http://api.twitter.com/1/users/profile_image/' . $item->author->name .'" width="55" height="55"'. '>' . '</a>' 
    

    The user name is parsed onto the end of the URL and then this is hyperlinked back the profile of the user. All the pictures are limited to ensure consistency.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题