<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/rss-style.xsl" type="text/xsl"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	    xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	     xmlns:dc="http://purl.org/dc/elements/1.1/"
	   xmlns:atom="http://www.w3.org/2005/Atom"
	     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	  xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>Displaying Twitter Photos via Entities &#8211; Terence Eden’s Blog</title>
	<atom:link href="https://shkspr.mobi/blog/2011/06/displaying-twitter-photos-via-entities/feed/" rel="self" type="application/rss+xml" />
	<link>https://shkspr.mobi/blog</link>
	<description>Regular nonsense about tech and its effects 🙃</description>
	<lastBuildDate>Thu, 01 May 2025 17:49:54 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://shkspr.mobi/blog/wp-content/uploads/2023/07/cropped-avatar-32x32.jpeg</url>
	<title>Displaying Twitter Photos via Entities &#8211; Terence Eden’s Blog</title>
	<link>https://shkspr.mobi/blog</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title><![CDATA[Displaying Twitter Photos via Entities]]></title>
		<link>https://shkspr.mobi/blog/2011/06/displaying-twitter-photos-via-entities/</link>
					<comments>https://shkspr.mobi/blog/2011/06/displaying-twitter-photos-via-entities/#comments</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Fri, 03 Jun 2011 15:43:19 +0000</pubDate>
				<category><![CDATA[mobile]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[dabr]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[twitter]]></category>
		<guid isPermaLink="false">http://shkspr.mobi/blog/?p=4150</guid>

					<description><![CDATA[Twitter has announced that it will soon open up a native photo sharing service.  Rather than using an external service like Embed.ly to retrieve thumbnails, all the data is embedded within Twitter Entities.  So, if you request a status using &#34;include_entities=true&#34;, you will be able to grab the image and display the thumbnail using the following code.  function twitter_get_media($status) {   …]]></description>
										<content:encoded><![CDATA[<p>Twitter has announced that it will soon open up a <a href="http://groups.google.com/group/twitter-development-talk/browse_thread/thread/99b451ce5d8259ce#">native photo sharing service</a>.</p>

<p>Rather than using an external service like Embed.ly to retrieve thumbnails, all the data is embedded within <a href="https://web.archive.org/web/20110611123536/http://dev.twitter.com/pages/tweet_entities">Twitter Entities</a>.</p>

<p>So, if you request a status using "<em>include_entities=true</em>", you will be able to grab the image and display the thumbnail using the following code.</p>

<pre><code class="language-php">function twitter_get_media($status) {
   if($status-&gt;entities-&gt;media) {

      $url = $status-&gt;entities-&gt;media[0]-&gt;media_url_https;

      $width = $status-&gt;entities-&gt;media[0]-&gt;sizes-&gt;thumb-&gt;w;
      $height = $status-&gt;entities-&gt;media[0]-&gt;sizes-&gt;thumb-&gt;h;

      $media_html = "&lt;a href="" . $url . "" target='_blank'&gt;";
      $media_html .=  "&lt;img src="" . $url . ":thumb" width="" . $width .
         "" height="" . $height . "" /&gt;";
      $media_html .= "&lt;/a&gt;&lt;br /&gt;";

      return $media_html;
   }
}
</code></pre>

<p>So, a tweet like this:
<a href="https://web.archive.org/web/20181224040939/https://twitter.com/twitter/status/76360760606986241">https://twitter.com/twitter/status/76360760606986241</a>
Will render like this (in Dabr):
<img src="https://shkspr.mobi/blog/wp-content/uploads/2011/06/Twitter-Dabr-Images.jpg" alt="Twitter Dabr Images" title="Twitter Dabr Images" width="317" height="528" class="aligncenter size-full wp-image-4154"></p>

<h2 id="notes"><a href="https://shkspr.mobi/blog/2011/06/displaying-twitter-photos-via-entities/#notes">Notes</a></h2>

<p>This is very rough and ready proof of concept code.  Beware of the following:</p>

<ul>
    <li>This will only take the first image from the tweet.</li>
    <li>Only images are supported - I'm not sure how their proposed video sharing will work.</li>
    <li>There's no error checking.</li>
    <li>In the above code, the https URL is used - if you want a non-SSL link, you'll need to remove the "_https"</li>
</ul>

<p>Enjoy!</p>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=4150&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2011/06/displaying-twitter-photos-via-entities/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
