Mercurial > pumpbridge
comparison src/facebook.coffee @ 12:f190abf340ef
fixed some problems with facebook (caused by developers.facebook.com) removed fql :D
author | Mathias Gebbe <mgebbe@intevation.de> |
---|---|
date | Thu, 12 Jun 2014 10:23:05 +0200 |
parents | 9d17cb5147ca |
children | c1b736a859c9 |
comparison
equal
deleted
inserted
replaced
11:9d17cb5147ca | 12:f190abf340ef |
---|---|
178 res.on "data", (chunk) -> | 178 res.on "data", (chunk) -> |
179 data += chunk | 179 data += chunk |
180 return | 180 return |
181 | 181 |
182 res.on "end", () -> | 182 res.on "end", () -> |
183 user = JSON.parse(data) | 183 if (data?) |
184 ### with app id ### | 184 try |
185 Routes.updateUserDB(user.id+'@facebook',user.name,user.name,user.link,user.picture.data.url) if user? | 185 user = JSON.parse(data) |
186 ### with link ### | 186 ### with app id ### |
187 Routes.updateUserDB(user.link,user.name,user.name,user.link,user.picture.data.url) if user? | 187 Routes.updateUserDB(user.id+'@facebook',user.name,user.name,user.link,user.picture.data.url) if user? |
188 ### with link ### | |
189 Routes.updateUserDB(user.link,user.name,user.name,user.link,user.picture.data.url) if user? | |
190 catch err | |
191 console.log "User Error" | |
188 return | 192 return |
189 | 193 |
190 ).on "error", (e) -> | 194 ).on "error", (e) -> |
191 console.log "Got error: " + e.message | 195 console.log "Got error: " + e.message |
192 | 196 |
193 return | 197 return |
194 | 198 |
195 ############################################## | 199 ############################################## |
196 ###### get facebook friends ###### | 200 ###### get facebook likes ###### |
197 ############################################## | 201 ############################################## |
198 getFriends = (user) -> | 202 getFriends = (user) -> |
203 me = user.user_pumpio | |
204 token = user.oauth_token | |
205 | |
206 FB.setAccessToken token | |
207 | |
208 FB.api "me/friends?limit=5000", | |
209 fields: [ | |
210 "id" | |
211 ] | |
212 , (res) -> | |
213 console.log res | |
214 if not res or res.error | |
215 console.log (if not res then "error occurred" else res.error) | |
216 | |
217 _.each res.data, (person) -> | |
218 getUserById(me,person.id,token) | |
219 return | |
220 | |
221 return | |
222 | |
223 ####################################### | |
224 ###### get user facebook3 ##### | |
225 ####################################### | |
226 getFriends3 = (user) -> | |
227 data = "" | |
228 id = user.user_ESN.substr(0,user.user_ESN.indexOf('@')) | |
229 token = user.oauth_token | |
230 options = | |
231 host: 'graph.facebook.com' | |
232 port: 443 | |
233 path: 'me/friends?limit=5000&access_token=' + token + '&client_id='+ appid + '&client_secret=' + secret | |
234 | |
235 https.get(options, (res) -> | |
236 console.log "Got response: " + res.statusCode | |
237 | |
238 res.on "data", (chunk) -> | |
239 data += chunk | |
240 return | |
241 | |
242 res.on "end", () -> | |
243 console.log data | |
244 return | |
245 | |
246 ).on "error", (e) -> | |
247 console.log "Got error: " + e.message | |
248 | |
249 return | |
250 | |
251 ############################################## | |
252 ###### get facebook friends2 ###### | |
253 ############################################## | |
254 getFriends2 = (user) -> | |
199 me = user.user_pumpio | 255 me = user.user_pumpio |
200 id = user.user_ESN.substr(0,user.user_ESN.indexOf('@')) | 256 id = user.user_ESN.substr(0,user.user_ESN.indexOf('@')) |
201 token = user.oauth_token | 257 token = user.oauth_token |
202 | 258 |
203 EdgeControl.removeEdges(me,'@facebook') | 259 EdgeControl.removeEdges(me,'@facebook') |
211 if not res or res.error | 267 if not res or res.error |
212 console.log (if not res then "error occurred" else res.error) | 268 console.log (if not res then "error occurred" else res.error) |
213 return | 269 return |
214 | 270 |
215 _.each res.data, (user) -> | 271 _.each res.data, (user) -> |
216 getUserById(me,user.uid2,token) | 272 getUserById(me,user.uid2,token) |
217 return | 273 return |
218 | 274 |
219 return | 275 return |
220 | 276 |
221 return | 277 return |
252 token = user.oauth_token | 308 token = user.oauth_token |
253 interval = config.interval | 309 interval = config.interval |
254 if not (interval?) | 310 if not (interval?) |
255 interval = 15 * 60 * 1000 # 900 000 ms (15min) | 311 interval = 15 * 60 * 1000 # 900 000 ms (15min) |
256 ts = Math.round(((new Date()).getTime() - interval)/1000) | 312 ts = Math.round(((new Date()).getTime() - interval)/1000) |
257 | 313 |
258 FB.setAccessToken token | 314 FB.setAccessToken token |
259 | 315 |
260 FB.api "me/home?limit=35&?since="+ts, | 316 FB.api "me/home?limit=35&?since="+ts, |
261 fields: [ | 317 fields: [ |
262 "id" | 318 "id" |