提前感谢您的时间。
我想知道如何通过传递Foursquare
类别ID 以编程方式获取Foursquare
类别的相应图像。
我已阅读API
文件,到目前为止还未能找到解决方法。
JSON
个网址会很棒,但OAuth
个应用也可以。
再次感谢。
答案 0 :(得分:2)
在official documentation中,您找不到任何通过ID检索类别的API方法
地点类别
https://api.foursquare.com/v2/venues/categories
返回应用于场地的分类的分层列表。
事实上,这个说明特别有趣:
设计客户端应用程序时,请仅下载此列表 每个会话一次,但也避免缓存此数据超过一个 一周,以避免陈旧的信息。
响应字段
包含子子类别和子子类别的类别数组。每 顶级类别包含id,name,pluralName,icon和 类别(子类别数组)。
Anywawy只是为了完成你的任务,从https://developer.foursquare.com/docs/explore#req=/venues/categories重新审核的JSON,你可以这样做:
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>
答案 1 :(得分:2)
根据官方文档: https://developer.foursquare.com/docs/api/venues/categories
需要构建各种尺寸的类别图标的零件。结合使用前缀(大小可以为32、44、64和88)和后缀,例如https://foursquare.com/img/categories/food/default_64.png。要获取具有灰色背景的图像,请在尺寸前使用bg_,例如https://foursquare.com/img/categories_v2/food/icecream_bg_32.png。
示例:
%timeit contains(Y, X)
%timeit naive_as_array(Y, X)
10 loops, best of 3: 185 ms per loop
1 loop, best of 3: 2.39 s per loop
无背景输出(大小:64):
{
"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
}
]
}
有背景(尺寸88):
https://ss3.4sqi.net/img/categories_v2/parks_outdoors/park_64.png