0

if anyone can help me I would be grateful, I am trying to solve but without success!

I have a dataframe with a list of IDs. With "Rfacebook's" package, I apply the "getPost's" function to receive all the data that I need. However, when I do the loop, only returns me a single result and repeats it dozens of times.

My code (edit with after contributions)

#final is a value in environment with all IDs that I need to do the getPost
verificador <- 1
listap <- c()
listap2 <- c()
p <- list()

while (verificador <= length(final)) {
  p[[verificador]] <- getPost(final[[verificador]], token, comments = F, reactions = T, n.reactions = 50000, api = NULL)
  verificador = verificador + 1
}

final(List of IDS):

 [1] "193944443965876_1884261211600849"
 [2] "193944443965876_1884261211600849"
 [3] "193944443965876_1884261211600849"
 [4] "193944443965876_1884261211600849"
 [5] "193944443965876_1884261211600849"
 [6] "193944443965876_1884261211600849"
 [7] "193944443965876_1884261211600849"
 [8] "193944443965876_1884261211600849"
... continue

Results of loop:

[[1]]
          from_id from_name
1 193944443965876       XYZ
                                                                                                                                                                                                                                                                                                                                                                        message
1 O lugar de uma t-shirt linda nunca será no fundo do armário! 
              created_time  type
1 2017-07-09T18:52:47+0000 video
                                                         link
1 https://www.facebook.com/XYZ/videos/1884261211600849/
                                id likes_count
1 193944443965876_1884261211600849        2729
  comments_count shares_count
1             69           44

[[2]]
          from_id from_name
1 193944443965876       XYZ
                                                                                                                                                                                                                                                                                                                                                                        message
1 O lugar de uma t-shirt linda nunca será no fundo do armário!
              created_time  type
1 2017-07-09T18:52:47+0000 video
                                                         link
1 https://www.facebook.com/XYZ/videos/1884261211600849/
                                id likes_count
1 193944443965876_1884261211600849        2729
  comments_count shares_count
1             69           44

continue...
Falves
  • 37
  • 1
  • 8
  • try defining p outside your loop. `p<-vector()` – Dave2e Jul 19 '17 at 23:28
  • `length(ids$final)`? – HubertL Jul 19 '17 at 23:31
  • 2
    Seems like `p` is a list? Try `p <- list()` before your loop, then `p[[verificador]] <- ...` in the loop. – Gregor Thomas Jul 20 '17 at 00:02
  • hey guys, really thanks for these help! :) I did the changes in the code, but my results are still the same: a lot of 1st repeated as a thousand times. :/ – Falves Jul 20 '17 at 02:12
  • `final` contains the same string `193944443965876_1884261211600849` repeated multiple times...which you use to `getPost` – CPak Jul 20 '17 at 03:21
  • This! @ChiPak You're right! When I changed the ids$final to final with index I didn't see that the previous loop (for to list IDs) wasn't work. But with the helps here I could resolve, finally! Thanks a lot to everybody! – Falves Jul 20 '17 at 04:49

0 Answers0