Created
August 24, 2011 19:20
-
-
Save aronwoost/1168933 to your computer and use it in GitHub Desktop.
Retrieve "anonymously" data from a foursquare checkin. You don't need to follow the person who checked in. However, the checkin must have been made public (e.g. via twitter)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<head> | |
<title>4sq image request</title> | |
<script type="text/javascript" src="jquery-1.6.2.js"></script> | |
<script type="text/javascript"> | |
// set the following appropriately | |
var testUrl4sq = "XXX", | |
bitlyUsername = "XXX", | |
bitlyApiKey = "XXX", | |
fsqAccessToken = "XXX"; | |
$(document).ready(function(){ | |
$.ajax({ | |
type: "GET", | |
url: "http://api.bitly.com/v3/expand?shortUrl="+encodeURIComponent(testUrl4sq)+"&login="+bitlyUsername+"&apiKey="+bitlyApiKey, | |
dataType: "json", | |
success: function (data) { | |
console.log(data); | |
if(data.status_txt !== "OK" || data.data.expand[0].error) { | |
console.log("bitly error"); | |
return; | |
} | |
var fsqUrl = data.data.expand[0].long_url, | |
fsqUrlMatch = fsqUrl.match(/checkin\/(.*?)\?s=(.*?)&.*?$/); | |
if(!fsqUrlMatch) { | |
console.log("something is wrong with the 4sq url"); | |
} | |
var checkinId = fsqUrlMatch[1]; | |
signature = fsqUrlMatch[2]; | |
$.ajax({ | |
type: "GET", | |
url: "https://api.foursquare.com/v2/checkins/"+checkinId+"?signature="+signature+"&oauth_token="+fsqAccessToken, | |
dataType: "json", | |
success: function (data) { | |
console.dir(data); | |
var imageUrl = data.response.checkin.photos.items[0].url; | |
console.log(imageUrl); | |
}, | |
error: function() { | |
console.log("4sq error"); | |
} | |
}); | |
}, | |
error: function() { | |
console.log("bitly error"); | |
} | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment