<?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>
	<copyright>© Terence Eden. 🄯 CC BY-SA. See https://shkspr.mobi/blog/copyright-and-copyleft/</copyright>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.3</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[Terence Eden]]></dc:creator>
		<pubDate>Tue, 15 Mar 2011 12:35:22 +0000</pubDate>
		<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>&lt;p&gt;"Oi!" shouted &lt;a href="http://whatleydude.com/"&gt;Whatleydude&lt;/a&gt;, "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....&lt;/p&gt;

&lt;p&gt;So, how do we go from &lt;a href="http://4sq.com/fgIWov"&gt;http://4sq.com/fgIWov&lt;/a&gt;
to
&lt;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"&gt;&lt;/p&gt;

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

&lt;p&gt;Get your &lt;a href="http://bit.ly/a/your_api_key/"&gt;Bit.ly API Key&lt;/a&gt;.&lt;/p&gt;

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

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

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

&lt;p&gt;Bit.ly gives us the URL which includes a checkin ID and a signature.&lt;/p&gt;

&lt;pre&gt;http://foursquare.com/edent/checkin/4d7e5b4f9df3f04d7400c394
   ?s=afH3jJg3L9HpLqVIwiqp-YpNL5k
&lt;/pre&gt;

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

&lt;p&gt;From this, we construct an API call to Foursquare.  It looks like this&lt;/p&gt;

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

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

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

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

&lt;p&gt;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.&lt;/p&gt;

&lt;pre lang="json"&gt;{
  "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
                  }
               ]
            },
&lt;/pre&gt;

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

&lt;p&gt;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.&lt;/p&gt;

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

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

&lt;p&gt;Dabr uses the &lt;a href="http://embed.ly/"&gt;awesome Embedly service&lt;/a&gt;.  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.&lt;/p&gt;

&lt;p&gt;Any questions, comments, or clarifications - please let me know in the comments box.&lt;/p&gt;
&lt;img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=3749&amp;amp;HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager"&gt;</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>
