Alexandr Alexandr - 1 year ago 96
Linux Question

What to write in a body of a request to GoogleDrive API?

I am trying to work with GoogleDrive via Linux console but I have problems with requests which require a body. All permissions are given. All other requests (without body) are working.

If I want to create a folder in the GoogleDrive it shows me an error.

wget --header="Host:" --header="Authorization: Bearer MY_TOKEN" --header="Content-Length: 18" --header="Content-Type: application/" --method=POST --body-data='{"title":"TemDir"}' '' -O result.html

Response is:

--2016-07-07 15:03:34--
Resolving (, 2a00:1450:4010:c08::5f
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 400 Bad Request
2016-07-07 15:03:35 ERROR 400: Bad Request.

When I send requests without a body they all work:

List first 3 files:

wget --header="Host:" --header="Authorization: Bearer MY_TOKEN" --method=GET '' -O result.html

Upload a video file:

wget --header='Host:' --header='Content-Type: video/mp4' --header='Content-Length: 9356131' --header='Authorization: Bearer MY_TOKEN' --post-file=test.mp4

Please, help me resolve this issue

Answer Source

You need to use correct syntax. Here is the working one for /v2. Though I will recommend you to move to /v3 as soon. This will create a folder of given name.

Using version /v2

wget  --header="Authorization: Bearer MY_TOKEN"  --header="Content-Type: application/json" --method=POST --body-data='{"title":"TemDir121", "mimeType": "application/"}' '' -O result.html

for /v3

wget  --header="Authorization: Bearer MY_TOKEN"  --header="Content-Type: application/json" --method=POST --body-data='{"name":"TemDir", "mimeType": "application/"}' '' -O result.html
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download