-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateCategoryIndex.php
43 lines (37 loc) · 1.12 KB
/
createCategoryIndex.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/*echo "Creating categories-file...";
ob_flush();
flush();
$arr = array();
createCategoryIndex();
echo "<br>Done!";*/
function createCategoryIndex(){
global $arr;
$CLIENT_ID = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$CLIENT_SECRET = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$json = file_get_contents("https://api.foursquare.com/v2/venues/categories?client_id=" . $CLIENT_ID
. "&client_secret=" . $CLIENT_SECRET . "&v=20150601");
$decoded = json_decode($json);
$cats = $decoded->response->categories;
foreach($cats as $cat){
addAllSubCategories($cat, $cat->id, $cat->name);
}
$file = fopen("categories.json", "w");
fwrite($file, json_encode($arr, JSON_FORCE_OBJECT));
fclose($file);
}
function addAllSubCategories($currentCategory, $parentCatID, $parentCatName){
global $arr;
$arr[$currentCategory->id] = array(
"parentCatID" => $parentCatID,
"parentCatName" => $parentCatName,
"catName" => $currentCategory->name
);
$subcats = $currentCategory->categories;
if(!is_null($subcats)){
foreach($subcats as $subcat){
addAllSubCategories($subcat, $parentCatID, $parentCatName);
}
}
}
?>