I'm trying to donwload a file i've uploaded to a Team Drive using the v3 method from drive().files().get() as described in documentation.
I can get the metadata, like file ID and permissions, but don't know how to access the actual binary content, e.g. to write it to a file. The file in question is a plain text file.
This is part of the code i'm using.
request = service.files().get(fileId=file_id, supportsTeamDrives=True)
pprint.pprint(request.to_json())
response = request.execute()
pprint.pprint(response)
And the response (from the pprints)
Request
{
"uri": "https://www.googleapis.com/drive/v3/files/1CxxxxxxxxxxxxHp?supportsTeamDrives=true&alt=json",
"method": "GET",
"body": null,
"headers": {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"user-agent": "google-api-python-client/1.7.8 (gzip)"
},
"methodId": "drive.files.get",
"resumable": null,
"response_callbacks": [],
"_in_error_state": false,
"body_size": 0,
"resumable_uri": null,
"resumable_progress": 0
}
File Metadata
{'id': '1CxxxxxxxxxxxxHp',
'kind': 'drive#file',
'mimeType': 'text/plain',
'name': 'test.txt',
'teamDriveId': 'XXXXXXXXXXXXXXX'}
I can access file metadata, but don't know how to get the file's contents, to write to a file.
I'm using the full access scope, "https://www.googleapis.com/auth/drive".
Documentation says "Gets a file's metadata or content by ID.", but it doesn't explain how.
Ok. After trying different options, i came to a solution mixing info from different posts.
1 - The get_media() method works in v3 but is not documented anywhere (even on v2 docs).
2 - io.BytesIO dindn't work, changed to FileIO.
The result code was something like this:
request = drive_service.files().get_media(fileId=file_id)
fh = io.FileIO(filename, "wb")
downloader = MediaIoBaseDownload(fh, request)
done = False
while done is False:
status, done = downloader.next_chunk()
Google Api documentation is really messy and inconsistent in so many ways.
Related
How do I upload muliple files in the same request using jodd HTTP?
I've tried something like the following but only the first file was posted.
HttpRequest httpRequest = HttpRequest
.post("http://srv:8080/api/dlapp/add-file-entry")
.form(
"title", "test",
"description", "Upload test",
"file", new File("d:\\a.jpg.zip"),
"file", new File("d:\\b.jpg.zip")
);
HttpResponse httpResponse = httpRequest.send();
That is the correct code. You simply add file parameters:
HttpRequest httpRequest = HttpRequest.post("localhost:8173/echo")
.form(
"title", "test",
"description", "Upload test",
"file1", temp1,
"file2", temp2
);
Nothing more, nothing less. There is the testcase that checks just that.
The easiest way to check is to fireup e.g. Wireshark on your local machine and simply inspect the request; there must be two files blocks in it.
Is it possible that your serverside, for some reason is not accepting files?
Do you use the latest version (v5.0.x)?
p.s. if you are sending two files, please use two different parameter names (e.g. file1, file2).
I was successful in publishing (POST) a JSON file in Zapier and creating a Storage for it. However, I´d like to access the JSON in Zapier Storage using a Python code run locally. I am able to access the storage with Python3, see that is something written there, but I cannot access the JSON contents.
import urllib
import json
import codecs
reader = codecs.getreader("utf-8")
access_token = "password"
def GetStorage(page_id, access_token):
url = 'https://hooks.zapier.com/url/'
response = urllib.request.urlopen(url)
data = json.load(reader(response))
return data
a=GetStorage(url, access_token)
print(a)
All I get is:
{'attempt': '5a539a49-65eb-44f8-a30e-e171faf7a680',
'id': '1b38d21a-0150-46df-98c1-490a0d04b565',
'request_id': '5a539a49-65eb-44f8-a30e-e171faf7a680',
'status': 'success'}
When in fact I need:
{'Name':'value',
'Address': 'value'
}
Any ideas ?
David here, from the Zapier Platform team.
You're close! hooks.zapier.com is the url we use for incoming webhooks, so we always reply with a 200 and the response body you're seeing.
Instead, use store.zapier.com. You'll also want to make sure to include your secret. A full request URL will look like:
https://store.zapier.com/api/records?secret=test
which will return arbitrary json data:
{
"name": "david",
"job": "programmer"
}
The full docs are in json here: https://store.zapier.com/
I've been following the Autodesk Model Derive API tutorial on
Extracting Data From a Source File and keep getting a Translation Failure when attempting to convert the uploaded source file to SVF.
I have tried .step, .sldprt, .stl and .igs files (supported file extensions here), but all seem to throw the same error message.
The request
def self.convert_to_svf(urn, key)
url = URI("https://developer.api.autodesk.com/modelderivative/v2/designdata/job")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
body = {"input": { "urn": "#{urn}", "compressedUrn": true, "rootFilename": "#{key}" }, "output": { "formats": [{ "type": "svf", "views": ["2d", "3d"] }] }}
request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/json'
request["authorization"] = 'Bearer ' + token
request.body = body.to_json
JSON.parse(http.request(request).read_body)
end
The response
{"type"=>"manifest", "hasThumbnail"=>"false", "status"=>"failed", "progress"=>"complete", "region"=>"US", "urn"=>"dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6aXNvcXVlLzE4Ynk4cG9pbnQ1X2dvb2R5ZWFyLmlncw", "derivatives"=>[{"name"=>"LMV Bubble", "hasThumbnail"=>"false", "status"=>"failed", "progress"=>"complete", "messages"=>[{"type"=>"error", "message"=>"Translation failure", "code"=>"TranslationWorker-InternalFailure"}], "outputType"=>"svf"}]}
I did not see an obvious issue in your code snippet, however may I know if you have uploaded the source file(s) in zip format or only the single file of the original format (say .step, .sldprt, .stl and .igs) ?
I had the practice on the relevant APIs. I tested with Inventor assembly (with sub-assemblies and parts) and AutoCAD drawing (with Xrefs). The endpoint can work well with compressedUrn = true, specifying root file, after I uploaded file package in a zip.
If compressedUrn = true, that means the source file is compressed (zip), but this applies to the composite files, i.e. a main file has some dependent files. If it is a single file which has no dependent files, upload the source file directly, then call/modelderivative/v2/designdata/job without specifying compressedUrn and
rootFilename.
If I misunderstood your question, could you provide a bit more information or a demo dataset? Note, do not post any data that is confidential to your company.
I am trying to use the Pivotal Tracker API to post a story using python. I am able to do so using the python requests module. The following is a sample code that I can use to create a new story:
payload = {"name":"Create story w/create label"}
requests.post('https://www.pivotaltracker.com/services/v5/projects/xxxxxx/stories', data=payload4, headers={'X-TrackerToken':token}).json()
for which the output is
{u'created_at': u'2015-03-04T18:47:28Z',
u'current_state': u'unscheduled',
u'id': xxxxxx,
u'kind': u'story',
u'labels': [],
u'name': u'Create story w/create label',
u'owner_ids': [],
u'project_id': xxxxxx,
u'requested_by_id': xxxxxx,
u'story_type': u'feature',
u'updated_at': u'2015-03-04T18:47:28Z',
u'url': u'https://www.pivotaltracker.com/story/show/xxxxxx'}
Great. Now, I want to create a story and add a label to it. According to the POST /projects/{project_id}/stories API on https://www.pivotaltracker.com/help/api/rest/v5, I should be able to format my json as follows and run a POST request:
payload = {"name":"Create story w/create label","labels":[{"name":"orbit"}]}
requests.post('https://www.pivotaltracker.com/services/v5/projects/xxxxxx/stories', data=payload, headers={'X-TrackerToken':token}).json()
however, I get the following 400 response:
{u'code': u'invalid_parameter',
u'error': u'One or more request parameters was missing or invalid.',
u'general_problem': u"'labels' must be an array of label values",
u'kind': u'error'}
From what I understand, the way I formatted the payload json is correct and the label resource json is formatted properly. I'm not sure if the error is on my end or if it is something else. If someone with knowledge of the API could provide some help, it would be much appreciated.
Thanks
Solved it, there' s a JSON encoding issue. We never told pivotal tracker that we were sending JSON. This code snippet works:
data = {
"labels": ["major request"],
"name": "some cool feature",
"description": "solve world hunger",
"comments": ["requested by not the 1%"]
}
headers = {'X-TrackerToken': TRACKER_TOKEN,
'Content-type': 'application/json',
'Accept': 'application/json'
}
return requests.post(url, headers=headers, data=json.dumps(data))
Need to tell the API that we are sending JSON and accepting JSON.
I'm using Google Chrome REST API to get information from my web server.
I use: Content-Type = "application/json"
and a Post command that includes groovy code inside the Payload (the header remains empty):
{
"aaa": "dan",
"bbb": "my_data",
"ccc": "my_type"
}
or sometimes the Post is empty also in the Payload
This works just fine (I'm getting the response in json format)
I want to post this command with VBA from excel so the response would get into a VBA variable, which I can then print into some cell in the worksheet. How do I do it?
Do I need to download some library for that?
I tried (without success):
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
URL = "[my_URL]"
objHTTP.Open "POST", URL, False
objHTTP.setRequestHeader "Content-type", "application/json"
Worksheets("sheet1").Cells(1, 1)=objHTTP
Please advise,
Needed to add:
objHTTP.setTimeouts 30000, 60000, 30000, 120000