Mercurial > pumpbridge
diff 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 |
line wrap: on
line diff
--- a/src/facebook.coffee Thu Jun 12 01:08:00 2014 +0200 +++ b/src/facebook.coffee Thu Jun 12 10:23:05 2014 +0200 @@ -180,11 +180,15 @@ return res.on "end", () -> - user = JSON.parse(data) - ### with app id ### - Routes.updateUserDB(user.id+'@facebook',user.name,user.name,user.link,user.picture.data.url) if user? - ### with link ### - Routes.updateUserDB(user.link,user.name,user.name,user.link,user.picture.data.url) if user? + if (data?) + try + user = JSON.parse(data) + ### with app id ### + Routes.updateUserDB(user.id+'@facebook',user.name,user.name,user.link,user.picture.data.url) if user? + ### with link ### + Routes.updateUserDB(user.link,user.name,user.name,user.link,user.picture.data.url) if user? + catch err + console.log "User Error" return ).on "error", (e) -> @@ -193,10 +197,62 @@ return ############################################## -###### get facebook friends ###### +###### get facebook likes ###### ############################################## getFriends = (user) -> me = user.user_pumpio + token = user.oauth_token + + FB.setAccessToken token + + FB.api "me/friends?limit=5000", + fields: [ + "id" + ] + , (res) -> + console.log res + if not res or res.error + console.log (if not res then "error occurred" else res.error) + + _.each res.data, (person) -> + getUserById(me,person.id,token) + return + + return + +####################################### +###### get user facebook3 ##### +####################################### +getFriends3 = (user) -> + data = "" + id = user.user_ESN.substr(0,user.user_ESN.indexOf('@')) + token = user.oauth_token + options = + host: 'graph.facebook.com' + port: 443 + path: 'me/friends?limit=5000&access_token=' + token + '&client_id='+ appid + '&client_secret=' + secret + + https.get(options, (res) -> + console.log "Got response: " + res.statusCode + + res.on "data", (chunk) -> + data += chunk + return + + res.on "end", () -> + console.log data + return + + ).on "error", (e) -> + console.log "Got error: " + e.message + + return + +############################################## +###### get facebook friends2 ###### +############################################## +getFriends2 = (user) -> + me = user.user_pumpio id = user.user_ESN.substr(0,user.user_ESN.indexOf('@')) token = user.oauth_token @@ -213,7 +269,7 @@ return _.each res.data, (user) -> - getUserById(me,user.uid2,token) + getUserById(me,user.uid2,token) return return @@ -254,7 +310,7 @@ if not (interval?) interval = 15 * 60 * 1000 # 900 000 ms (15min) ts = Math.round(((new Date()).getTime() - interval)/1000) - + FB.setAccessToken token FB.api "me/home?limit=35&?since="+ts,