Skip to content

Commit

Permalink
getNetwork now works with v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pablobarbera committed Jan 4, 2015
1 parent a2b753f commit c6e335a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Rfacebook/R/getNetwork.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,16 @@ getNetwork <- function(token, format='edgelist', verbose=TRUE){
n <- length(friends$id)
if (verbose==TRUE){ pb <- txtProgressBar(min=1,max=n, style=3) }
for (i in 1:n){
query <- paste0("https://graph.facebook.com/v1.0/me/mutualfriends/", friends$id[i], "?")
content <- callAPI(query, token)
mutual.friends <- unlist(lapply(content[[1]], '[[', 'name'))
if (tkversion=="v1"){
query <- paste0("https://graph.facebook.com/v1.0/me/mutualfriends/", friends$id[i], "?")
content <- callAPI(query, token)
mutual.friends <- unlist(lapply(content[[1]], '[[', 'name'))
}
if (tkversion=="v2"){
query <- paste0("https://graph.facebook.com/", friends$id[i],"?fields=context.fields(mutual_friends)")
content <- callAPI(query, token)
mutual.friends <- unlist(lapply(content[[1]][[1]]$data, '[[', 'name'))
}
for (friend in mutual.friends){
edge.list <- rbind(edge.list, c(friends$name[i], friend))
}
Expand Down
9 changes: 9 additions & 0 deletions test/unit-tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,15 @@ load("~/Dropbox/credentials/facebook/tokenv2")
mat <- getNetwork(token=fb_oauth, format="adj.matrix")
str(mat)

## test of Facebook token, Unversioned
token <- tokenv1
mat <- getNetwork(token=token, format="adj.matrix")
str(mat)

## test of Facebook token, v2.x
token <- tokenv2
mat <- getNetwork(token=token, format="adj.matrix")
str(mat)

##########################################
## getNewsfeed
Expand Down

0 comments on commit c6e335a

Please sign in to comment.