<?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>4SQ &#8211; Terence Eden’s Blog</title>
	<atom:link href="https://shkspr.mobi/blog/tag/4sq/feed/" rel="self" type="application/rss+xml" />
	<link>https://shkspr.mobi/blog</link>
	<description>Regular nonsense about tech and its effects 🙃</description>
	<lastBuildDate>Fri, 06 Oct 2023 12:53:53 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://shkspr.mobi/blog/wp-content/uploads/2023/07/cropped-avatar-32x32.jpeg</url>
	<title>4SQ &#8211; Terence Eden’s Blog</title>
	<link>https://shkspr.mobi/blog</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title><![CDATA[Getting Images from a Foursquare Checkin]]></title>
		<link>https://shkspr.mobi/blog/2011/03/getting-images-from-a-foursquare-checkin/</link>
					<comments>https://shkspr.mobi/blog/2011/03/getting-images-from-a-foursquare-checkin/#respond</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Tue, 15 Mar 2011 12:35:22 +0000</pubDate>
				<category><![CDATA[/etc/]]></category>
		<category><![CDATA[4SQ]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[bit.ly]]></category>
		<category><![CDATA[dabr]]></category>
		<category><![CDATA[FourSquare]]></category>
		<category><![CDATA[programming]]></category>
		<guid isPermaLink="false">http://shkspr.mobi/blog/?p=3749</guid>

					<description><![CDATA[&#34;Oi!&#34; shouted Whatleydude, &#34;Get Dabr to show images from foursquare checkins!&#34; &#34;Righty-ho sir!&#34; I said.  I started coding furiously.  Of course, things are never quite as simple as I first thought....  So, how do we go from http://4sq.com/fgIWov to   1 Expand the URL  Get your Bit.ly API Key.  http://api.bitly.com/v3/expand    ?shortUrl=http://4sq.com/fgIWov    &#38;login=YOUR_BIT_LY_USERNAME   …]]></description>
										<content:encoded><![CDATA[<p>"Oi!" shouted <a href="http://whatleydude.com/">Whatleydude</a>, "Get Dabr to show images from foursquare checkins!"
"Righty-ho sir!" I said.  I started coding furiously.  Of course, things are never quite as simple as I first thought....</p>

<p>So, how do we go from <a href="http://4sq.com/fgIWov">http://4sq.com/fgIWov</a>
to
<img src="https://shkspr.mobi/blog/wp-content/uploads/2011/03/4sq.jpg" alt="Photo of a MacBook. The decal sticker is of Iron Man. His hand blaster is replaced with the Apple logo." width="236" height="329" class="aligncenter size-full wp-image-47785"></p>

<h2 id="1-expand-the-url"><a href="https://shkspr.mobi/blog/2011/03/getting-images-from-a-foursquare-checkin/#1-expand-the-url">1 Expand the URL</a></h2>

<p>Get your <a href="http://bit.ly/a/your_api_key/">Bit.ly API Key</a>.</p>

<pre>http://api.bitly.com/v3/expand
   ?shortUrl=http://4sq.com/fgIWov
   &amp;login=YOUR_BIT_LY_USERNAME
   &amp;apiKey=YOUR_BIT_LY_API_KEY
   &amp;format=txt
</pre>

<p>You can, if you prefer, get the info back in JSON or XML. See the <a href="http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/expand">Bit.ly API Expand Documentation</a>.</p>

<h2 id="2-the-foursquare-url"><a href="https://shkspr.mobi/blog/2011/03/getting-images-from-a-foursquare-checkin/#2-the-foursquare-url">2 The Foursquare URL</a></h2>

<p>Bit.ly gives us the URL which includes a checkin ID and a signature.</p>

<pre>http://foursquare.com/edent/checkin/4d7e5b4f9df3f04d7400c394
   ?s=afH3jJg3L9HpLqVIwiqp-YpNL5k
</pre>

<h2 id="3-the-foursquare-api-call"><a href="https://shkspr.mobi/blog/2011/03/getting-images-from-a-foursquare-checkin/#3-the-foursquare-api-call">3 The Foursquare API Call</a></h2>

<p>From this, we construct an API call to Foursquare.  It looks like this</p>

<pre>https://api.foursquare.com/v2/checkins/4d7e5b4f9df3f04d7400c394
   ?signature=afH3jJg3L9HpLqVIwiqp-YpNL5k
   &amp;oauth_token=YOUR_FOURSQUARE_OAUTH_TOKEN
</pre>

<p><strong>NOTE</strong> the Foursquare URL says <em>?s=</em> whereas the API call requires <em>?signature=</em>
That caused me more frustration than it should...</p>

<p>Getting your OAuth token is a little cumbersome - follow the steps at the <a href="http://developer.foursquare.com/docs/oauth.html">Foursquare Developers site</a>.</p>

<h2 id="4-the-json-response"><a href="https://shkspr.mobi/blog/2011/03/getting-images-from-a-foursquare-checkin/#4-the-json-response">4 The JSON Response</a></h2>

<p>I'll cut the cruft out of here, so you only see what you need to display images.
The response gives us the link to the full sized image - as well as several different sizes should you wish to display thumbnails.</p>

<pre lang="json">{
  "meta":{
     "code":200
  },
  "response":{
     "checkin":{
        },
   ...
   "photos":{
      "count":1,
      "items":[
         {
            "id":"4d7e5b4f9df3f04d7400c394",
            "createdAt":1300184596,
            "url":"http://playfoursquare.s3.amazonaws.com/pix/A.jpg",
            "sizes":{
               "count":4,
               "items":[
                  {
                     "url":"http://playfoursquare.s3.amazonaws.com/pix/B.jpg",
                     "width":720,"height":540
                  },
                  {
                     "url":"http://playfoursquare.s3.amazonaws.com/derived_pix/C.jpg",
                     "width":300,"height":300
                  },
                  {
                     "url":"http://playfoursquare.s3.amazonaws.com/derived_pix/D.jpg",
                     "width":100,"height":100
                  },
                  {
                     "url":"http://playfoursquare.s3.amazonaws.com/derived_pix/E.jpg",
                     "width":36,
                     "height":36
                  }
               ]
            },
</pre>

<h2 id="5-gotchas"><a href="https://shkspr.mobi/blog/2011/03/getting-images-from-a-foursquare-checkin/#5-gotchas">5 Gotchas</a></h2>

<p>Again, nothing in life is easy.  Not all foursquare checkins have an image associated with them.  In which case, we can do one of three things.</p>

<ol>
    <li>Display no image</li>
    <li>Display the user's avatar - if it's public</li>
    <li>Display an image of the venue - or one of the icons associated with it.</li>
</ol>

<h2 id="6-embed-ly"><a href="https://shkspr.mobi/blog/2011/03/getting-images-from-a-foursquare-checkin/#6-embed-ly">6 Embed.ly</a></h2>

<p>Dabr uses the <a href="http://embed.ly/">awesome Embedly service</a>.  Rather than having hundreds of different regular expressions and API calls to get embedded images, Embed.ly gives us a single end point to call.
So, rather than rewrite huge chunks of Dabr's code, I've submitted this to the clever-clogs behind Embed.ly - that way, everyone can benefit.</p>

<p>Any questions, comments, or clarifications - please let me know in the comments box.</p>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=3749&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2011/03/getting-images-from-a-foursquare-checkin/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
