thanks in advance for your time.
I would like to know how can I get the corresponding image of a Foursquare category programmatically by passing the Foursquare category ID.
I have read the API documents and so far have not been able to find a solution for this.
A JSON url would be great, but a OAuth app can work as well.
Thanks again.
According to the official docs: https://developer.foursquare.com/docs/api/venues/categories
Pieces needed to construct category icons at various sizes. Combine prefix with a size (32, 44, 64, and 88 are available) and suffix, e.g. https://foursquare.com/img/categories/food/default_64.png. To get an image with a gray background, use bg_ before the size, e.g. https://foursquare.com/img/categories_v2/food/icecream_bg_32.png.
Sample:
{
"categories":[
{
"id":"4bf58dd8d48988d163941735",
"name":"Park",
"pluralName":"Parks",
"shortName":"Park",
"icon":{
"prefix":"https://ss3.4sqi.net/img/categories_v2/parks_outdoors/park_",
"suffix":".png"
},
"primary":true
}
]
}
Output without background (size: 64):
https://ss3.4sqi.net/img/categories_v2/parks_outdoors/park_64.png
With background (size 88):
https://ss3.4sqi.net/img/categories_v2/parks_outdoors/park_bg_88.png
In the official documentation you can't find any API method to retrieve category by id
Venue Categories
https://api.foursquare.com/v2/venues/categories
Returns a hierarchical list of categories applied to venues.
In fact this note is particular interesting:
When designing client applications, please download this list only once per session, but also avoid caching this data for longer than a week to avoid stale information.
The Response fields
An array of categories containing sub- and sub-sub- categories. Each top-level category contains a id, name, pluralName, icon, and categories (an array of child categories).
Anywawy just to achieve your task, from a JSON retrived by https://developer.foursquare.com/docs/explore#req=/venues/categories, you can do something like this:
http://jsfiddle.net/InferOn/u8q6u/1/
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<script>
// sample categories JSON
var p = {
meta: {
code: 200
},
notifications: [
{
type: "notificationTray",
item: {
unreadCount: 0
}
}
],
response: {
categories: [
{
id: "4fceea171983d5d06c3e9823",
name: "Acquario",
pluralName: "Acquari",
shortName: "Acquario",
icon: {
prefix: "https://ss1.4sqi.net/img/categories_v2/arts_entertainment/aquarium_",
suffix: ".png"
},
categories: [
{
id: "4bf58dd8d48988d134941735",
name: "Studio di danza",
pluralName: "Studi di danza",
shortName: "Studio di danza",
icon: {
prefix: "https://ss1.4sqi.net/img/categories_v2/arts_entertainment/performingarts_dancestudio_",
suffix: ".png"
}
},
{
id: "4bf58dd8d48988d135941735",
name: "Teatro indie",
pluralName: "Teatri con produttori indipendenti",
shortName: "Produttore indipendente",
icon: {
prefix: "https://ss1.4sqi.net/img/categories_v2/arts_entertainment/performingarts_indieoffbroadway_",
suffix: ".png"
}
}
]
},
{
id: "4bf58dd8d48988d1e1931735",
name: "Sala Giochi",
pluralName: "Sale Giochi",
shortName: "Sala Giochi",
icon: {
prefix: "https://ss1.4sqi.net/img/categories_v2/arts_entertainment/arcade_",
suffix: ".png"
},
categories: []
}
]
}
}
function customFilter(object) {
if (object.hasOwnProperty('id') && object["id"] == '4bf58dd8d48988d134941735')
return object;
for (var i = 0; i < Object.keys(object).length; i++) {
if (typeof object[Object.keys(object)[i]] == "object") {
o = customFilter(object[Object.keys(object)[i]]);
if (o != null)
return o;
}
}
return null;
}
var result = customFilter(p);
alert(result['icon']['prefix'] + result['icon']['suffix']);
</script>
</body>
</html>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With