Open GoogleCodeExporter opened 8 years ago
Hi Thanks for writing in. This is an issue we are aware of and a consequence of
the client libraries stripping the filename from POST body information. CURL
can be used to upload a file and the filename remains in the POST body and it
will be preserved in the UI.
Original comment by mcoh...@google.com
on 16 Nov 2015 at 4:53
[deleted comment]
Hi mcoh...@google.com
I wasn't sure whether to post here or in the Groups forum
(https://groups.google.com/forum/#!topic/google-analytics-management-api/GkA6bA0
MTPo).
This filename issue is a problem for people uploading multiple files at around
the same time. No filename makes debugging difficult. If one of your uploads
fails for some reason, being clear about which files have gone in successfully
is very helpful.
I'm working on a Python project, but your note about cURL gave me hope, and
I've spent hours now with a bash script trying to achieve what you describe.
I've been able successfully to cURL uploads in as media, resumable and
multipart types but I cannot get the filename to show in the GA UI by any means.
Please can you help, by providing detail specifying the cURL parameters and
request body that will work?
Thanks very much
Kevin
Original comment by kevin.jo...@croud.co.uk
on 26 Jan 2016 at 11:01
curl -X POST -F "upload=@YOURFILENAME.csv;type=application/octet-stream"
"https://www.googleapis.com/upload/analytics/v3/management/accounts/XXXXXX/webpr
operties/UA-XXXXXX-1/customDataSources/CUSTOMDATASOURCEID/uploads?access_token=y
a29.REPLACEWIHTYOURVALIDTOKEN" -v
Original comment by mcoh...@google.com
on 26 Jan 2016 at 11:08
[deleted comment]
Thanks very much! I really wish I'd asked sooner :)
This works perfectly, and for Python you can use pycURL. This is the function
I'm using.
import pycurl
import json
def curlUpload(accountId, webPropertyId, customDataSourceId, csv):
credential_path = 'PATHTOYOURCREDENTIALSJSONFILE'
f = open(credential_path)
googleAccessToken = json.loads(f.read())['access_token']
c = pycurl.Curl()
c.setopt(c.URL, 'https://www.googleapis.com/upload/analytics/v3/management/accounts/' + accountId + '/webproperties/' + webPropertyId + '/customDataSources/' + customDataSourceId + '/uploads?access_token=' + googleAccessToken)
c.setopt(c.HTTPPOST, [
('fileupload', (
c.FORM_FILE, csv,
c.FORM_CONTENTTYPE, 'application/octet-stream'
)),
])
c.perform()
c.close()
Kevin
Original comment by kevin.jo...@croud.co.uk
on 27 Jan 2016 at 6:45
Original issue reported on code.google.com by
powermya...@gmail.com
on 12 Nov 2015 at 2:07Attachments: