Created
February 12, 2017 17:29
-
-
Save mkozjak/b8b29a0a6b1d1210222f673c5b2c2926 to your computer and use it in GitHub Desktop.
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
var https = require("https") | |
https.get("https://graph.facebook.com/v2.8/oauth/access_token?client_id=1237292836347210&client_secret=1418aa5b52dd2c2e4a2c55174f5b547b&grant_type=client_credentials", (res) => { | |
let body = "" | |
res.on("data", (data) => body += data.toString()) | |
res.on("end", () => { | |
let token = JSON.parse(body).access_token | |
https.get("https://graph.facebook.com/v2.8/search" | |
+ "?type=place¢er=45.8150,15.9819&distance=50000" | |
+ "&limit=1000&fields=id&access_token=" | |
+ token, (r) => { | |
let body2 = "" | |
r.on("data", data => body2 += data.toString()) | |
r.on("end", () => { | |
data = JSON.parse(body2) | |
let ids = [] | |
for (let i = 0; i < 50 ; i++) { | |
ids.push(data.data[i].id) | |
} | |
let global_loc_id = ids[0] | |
// get location name from location id | |
https.get("https://graph.facebook.com/v2.8/" + | |
global_loc_id + "?access_token=" + token + | |
"&fields=location", (ra) => { | |
ra.on("data", data => console.log(data.toString())) | |
}) | |
let eventsFields = [ | |
"id", | |
"type", | |
"name", | |
"cover.fields(id,source)", | |
"picture.type(large)", | |
"description", | |
"start_time", | |
"end_time", | |
"category", | |
"attending_count", | |
"declined_count", | |
"maybe_count", | |
"noreply_count" | |
] | |
// get events based on location id | |
https.get("https://graph.facebook.com/v2.8/?ids=" + ids.join(",") + | |
"&access_token=" + token + | |
"&fields=id,name,about,emails,cover.fields(id,source)," + | |
"picture.type(large),location,events.fields(" + | |
eventsFields.join(",") + | |
").since(" + (new Date().getTime()/1000).toFixed() + ")", (rab) => { | |
let events = "" | |
rab.on("data", resl => events += resl.toString()) | |
rab.on("end", () => { | |
let results = [] | |
let obj = JSON.parse(events) | |
Object.getOwnPropertyNames(obj).forEach(function(val) { | |
let venue = obj[val] | |
if (venue.events && venue.events.data.length > 0) { | |
let ev_count = venue.events.data.length | |
for (let i = 0; i < ev_count; i++) { | |
console.log( | |
`name: ${venue.events.data[i].name}, | |
category: ${venue.events.data[i].category || 'Most popular'}, | |
starting: ${venue.events.data[i].start_time}, | |
attending: ${venue.events.data[i].attending_count}`) | |
} | |
} | |
}) | |
}) | |
}) | |
}) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment