Mercurial > pumpbridge
comparison src/facebook.coffee @ 10:ccf1d9e741bd
corrected google apikey query, removed facebook query language
author | Mathias Gebbe <mgebbe@intevation.de> |
---|---|
date | Wed, 11 Jun 2014 23:43:28 +0200 |
parents | 6fd0a307850f |
children | 9d17cb5147ca |
comparison
equal
deleted
inserted
replaced
9:8363d4970c75 | 10:ccf1d9e741bd |
---|---|
191 console.log "Got error: " + e.message | 191 console.log "Got error: " + e.message |
192 | 192 |
193 return | 193 return |
194 | 194 |
195 ############################################## | 195 ############################################## |
196 ###### get facebook friends /remove all ###### | 196 ###### get facebook friends ###### |
197 ############################################## | 197 ############################################## |
198 getFriends = (user) -> | 198 getFriends = (user) -> |
199 me = user.user_pumpio | 199 me = user.user_pumpio |
200 id = user.user_ESN.substr(0,user.user_ESN.indexOf('@')) | |
201 token = user.oauth_token | 200 token = user.oauth_token |
202 | 201 |
203 EdgeControl.removeEdges(me,'@facebook') | 202 EdgeControl.removeEdges(me,'@facebook') |
204 EdgeControl.removeEdges(me,'www.facebook.com') | 203 EdgeControl.removeEdges(me,'www.facebook.com') |
205 | 204 |
206 FB.setAccessToken token | 205 FB.setAccessToken token |
207 FB.api "fql", | 206 |
208 q: "SELECT uid2 FROM friend WHERE uid1 = me()" | 207 FB.api "me/friends?limit=500", |
209 , (res) -> | |
210 if not res or res.error | |
211 console.log (if not res then "error occurred" else res.error) | |
212 return | |
213 | |
214 _.each res.data, (user) -> | |
215 getUserById(me,user.uid2,token) if user.id? | |
216 return | |
217 | |
218 return | |
219 | |
220 return | |
221 | |
222 ############################################## | |
223 ###### get facebook likes ###### | |
224 ############################################## | |
225 getPages = (user) -> | |
226 me = user.user_pumpio | |
227 token = user.oauth_token | |
228 | |
229 FB.setAccessToken token | |
230 | |
231 FB.api "me/likes", | |
232 fields: [ | 208 fields: [ |
233 "id" | 209 "id" |
234 ] | 210 ] |
235 , (res) -> | 211 , (res) -> |
236 if not res or res.error | 212 if not res or res.error |
238 | 214 |
239 _.each res.data, (page) -> | 215 _.each res.data, (page) -> |
240 getUserById(me,page.id,token) if user.id? | 216 getUserById(me,page.id,token) if user.id? |
241 return | 217 return |
242 | 218 |
219 return | |
220 | |
221 | |
222 ############################################## | |
223 ###### get facebook likes ###### | |
224 ############################################## | |
225 getPages = (user) -> | |
226 me = user.user_pumpio | |
227 token = user.oauth_token | |
228 | |
229 FB.setAccessToken token | |
230 | |
231 FB.api "me/likes?limit=5000", | |
232 fields: [ | |
233 "id" | |
234 ] | |
235 , (res) -> | |
236 if not res or res.error | |
237 console.log (if not res then "error occurred" else res.error) | |
238 | |
239 _.each res.data, (page) -> | |
240 getUserById(me,page.id,token) if user.id? | |
241 return | |
243 | 242 |
244 return | 243 return |
245 | 244 |
246 | 245 |
247 ####################################### | 246 ####################################### |
254 interval = 15 * 60 * 1000 # 900 000 ms (15min) | 253 interval = 15 * 60 * 1000 # 900 000 ms (15min) |
255 ts = Math.round(((new Date()).getTime() - interval)/1000) | 254 ts = Math.round(((new Date()).getTime() - interval)/1000) |
256 | 255 |
257 FB.setAccessToken token | 256 FB.setAccessToken token |
258 | 257 |
259 FB.api "me/home?limit=25&?since="+ts, | 258 FB.api "me/home?limit=35&?since="+ts, |
260 fields: [ | 259 fields: [ |
261 "id" | 260 "id" |
262 "type" | 261 "type" |
263 "from" | 262 "from" |
264 "privacy" | 263 "privacy" |
379 token = token | 378 token = token |
380 fields = 'fields=id,name,picture,link' | 379 fields = 'fields=id,name,picture,link' |
381 options = | 380 options = |
382 host: 'graph.facebook.com' | 381 host: 'graph.facebook.com' |
383 port: 443 | 382 port: 443 |
384 path: '/' + id + '?access_token=' + token + '&' + fields | 383 path: '/' + id + '?access_token=' + token + '&client_secret=' + secret + '&' + fields |
385 | 384 |
386 https.get(options, (res) -> | 385 https.get(options, (res) -> |
387 #console.log "Got response: " + res.statusCode | 386 #console.log "Got response: " + res.statusCode |
388 | 387 |
389 res.on "data", (chunk) -> | 388 res.on "data", (chunk) -> |