I am using map()
to get post data from Facebook using the following code:
posts_data <- map(posts$query_id, getPost, token = fb_oauth, n = 1000)
However, some of the query_id
observations are incorrect, or are shared events, which the API cannot retrieve and gives me an error like:
Error in callAPI(url = url, token = token, api = api) :
Unsupported get request. Object with ID '1816137521765810_1832190963493790' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api
I understand that I can use possibly()
to continue to make calls while returning an output for those errors, so that the function does not stop. But I do not know how to use possibly()
and map()
together, since possibly() only takes a function as an argument, and doesn't allow me to pass additional arguments to that function.
possibly
takes a function as an argument, but it returns another function, which accepts the same arguments as its input does. So you should just be able to do:
posts_data <- map(posts$query_id,
possibly(getPost, otherwise = NA_character_),
token = fb_oauth, n = 1000)