Rfacebook icon indicating copy to clipboard operation
Rfacebook copied to clipboard

getPage() since value UNIX timestamp is not working

Open yiuking1 opened this issue 7 years ago • 4 comments

for getPage(page, token, n = 25, since = NULL, until = NULL, feed = FALSE, reactions = FALSE, verbose = TRUE, api = NULL)

If I put a "UNIX timestamp" in to "since". It only accept "date value" not include time value. For Example: if I input timestamp 1512371885. (GMT: 2017-Dec-4 Monday 07:18:05) It only accept value 2017-Dec-4.

Source Code: if (!is.null(since)){ dates <- formatFbDate(df$created_time, 'date') mindate <- min(dates) sincedate <- as.Date(since) } if (is.null(since)){ sincedate <- as.Date('1970/01/01') mindate <- as.Date(Sys.time()) }

yiuking1 avatar Dec 04 '17 07:12 yiuking1

I get the same error:

Error in as.Date.numeric(since): 'origin' must be supplied

What I tried to do is getting posts that are newer than the newest one in a data set ("page_data"):

newest <- as.numeric(lubridate::ymd_hms(max(page_data$created_time)))
Rfacebook::getPage(pagename, token = token, n = n_posts,
                   reactions = reactions, feed = feed,
                   since = newest + 1)

And I am pretty sure it worked last week.

jogrue avatar Dec 05 '17 13:12 jogrue

Now, when I think about it: it probably did not work last week. I now also got what you were hinting at @yiuking1.

The problem is the code from getPage you pasted in the initial post (somehow the formatting went away, so I will post it again):

	if (!is.null(since)){
		dates <- formatFbDate(df$created_time, 'date')
		mindate <- min(dates)
		sincedate <- as.Date(since)
	}

as.Date(...) needs an origin (afaik 1970-01-01 for UNIX timestamps) when fed with a numeric date. It only works for character vectors in the format "%Y-%m-%d" and "%Y/%m/%d". So, this also does not match the documentation:

A UNIX timestamp or strtotime data value that points to the start of the time range to be searched. For more information on the accepted values, see: http://php.net/manual/en/function.strtotime.php

I think a good and easy solution would be to only accept a certain datetime format and then deal with it accordingly inside the Rfacebook functions.

jogrue avatar Dec 05 '17 14:12 jogrue

I've faced with that issue on getPage. Is there a way to solve it without editing the source code? Instead of UNIX timestamp can we feed strtotime data?

plazma-prizma avatar Dec 16 '17 09:12 plazma-prizma

Without touching Rfacebook code, only character vectors in the format "%Y-%m-%d" and "%Y/%m/%d" work (AFAIK). So you won't be able to provide the exact time.

jogrue avatar Dec 18 '17 10:12 jogrue