Skip to content

Instantly share code, notes, and snippets.

@IronistM
Created October 18, 2013 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IronistM/7039991 to your computer and use it in GitHub Desktop.
Save IronistM/7039991 to your computer and use it in GitHub Desktop.
postDailyCustomDataSource = function(filename = "./YandexUpload/cost.data.splits.2013_02_11.csv",
accountId=GA.profiles$accountId[52], #uploading to 52nd accountId
webPropertyId=GA.profiles$webPropertyId[52],
customDataSourceId="XXXXX",
date = '2013-02-11',
access_token = MEtoken) {
# Verified this is correct URL as it works in curl
url2 <- paste0('https://www.googleapis.com/upload/analytics/v3/management/accounts/', accountId ,
'/webproperties/', webPropertyId,
'/customDataSources/', customDataSourceId,
'/dailyUploads/', date, '/uploads?',
'access_token=', access_token,
'&type=cost',
'&appendNumber=1'
);
# Returns "Error: Bad Request"
# rawData <- postForm(url2,
# upload = fileUpload(filename = filename,
# contentType = "application/octet-stream"
# ),
# .encoding = "utf-8",
# style = 'POST')
# Works, uploads file
syscommand <- system(paste0('curl -X POST "',url2,'" -F "upload=@',filename,';type=application/octet-stream"'),
intern = TRUE)
#return(rawData)
return(syscommand)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment