R/apiCall.R

Defines functions apiCall

Documented in apiCall

apiCall = function(id, ad.account, token, date.from, date.to) {
  #' @title Make API call to get data of fanpage fans
  #' @name apiCall
  #' @aliases apiCall
  #'
  #' @description
  #' \code{apiCall} makes API call to get data of fanpage fans from Facebook Graph API
  #'
  #' @param id id of fanpage
  #' @param ad.account ad account from Facebook
  #' @param token token from Facebook
  #' @param date.from start date of research
  #' @param date.to end date of research
  #'
  #' @usage apiCall(id, ad.account, token, date.from, date.to)
  #'
  #' @return url to JSON with data
  #' @examples apiCall(450100695180891,224371541,
  #' 'EAADd6gCguI8BABCa5jew3mZBSV4qjEZAdrYHeDDf8zfwCZAXZCgLr9zXtrU6FsEGdfh44gZB1CMMxo7k7ZAXtal615Pb2r9H6CLfqxhK2JrvVWF3LDykayAToJ34eYlvQyYXbXygTDVrC8c5OoYlXWp4ZAT389vgk0ZD',
  #' '2017-01-01', '2017-05-01')
  #'
  #' @export apiCall

  api.url = "https://graph.facebook.com/"
  api.version = "v2.9"
  date.from = convertDateToTimestamp(date.from)
  date.to = convertDateToTimestamp(date.to)

  url = paste0(api.url, api.version, '/', id, '/insights?access_token=', token,
               '&pretty=1&metric=page_fans&since=', date.from, '&until=', date.to)
  return(url)
}
karolgileta/FanpageData documentation built on June 24, 2017, 8:41 a.m.