Unable to subscribe to Google Drive push notifications - google-drive-api

Based on:
https://developers.google.com/drive/api/v3/push
I do not understand where to get the auth_token_for_current_user from.
I have service account credentials, also an OAuth token. I have tried the access_token, refresh_token... I do not understand what token this is supposed to be.
curl --location --request POST 'https://www.googleapis.com/drive/v3/changes/watch' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer 1//064ToBH1n***' \
--data-raw '{
"id":"***",
"type": "web_hook",
"address": "https://***.cloudfunctions.net/verify"
}'
returns:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
Thanks for any help.

Related

Autodesk.Forge.DerivativesApi.GetManifest() failed status

I've trying to process a file that uploads+renders fine on the demo autodesk viewer (i.e. viewer.autodesk.com). The GetManifest result has a progress of "complete" but a status of "failed". If I dump the contents of the GetManifest() call I get the following which has Unrecoverable exit code from extractor: -1073741829 in the message. Wondering why it completes and renders on the online Autodesk viewer. The translation completes w\ "success", but when I try and get the manifest (so that I can download the derivatives), it fails on the GetManifest() call.
? manifest.ToString()
"{
\r\n "urn": "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6a2FodWFtb2RlbHMvOWNjNjA2Njg2NGIwNDViNDg5NjhhNDMxNjI1NmEzNTMuSUZD",
\r\n "derivatives": [
\r\n {
\r\n "hasThumbnail": "false",\r\n "name": "LMV Bubble",\r\n "progress": "complete",\r\n "messages": [
\r\n {\r\n "type": "error",
\r\n "message": "Unrecoverable exit code from extractor: -1073741829",
\r\n "code": "TranslationWorker-InternalFailure"\r\n }\r\n ],\r\n
"outputType": "svf",\r\n "status": "failed"\r\n }\r\n ],
\r\n "hasThumbnail": "false",\r\n "progress": "complete",\r\n "type": "manifest",\r\n "region": "US",\r\n "version": "1.0",\r\n "status": "failed"\r\n}"
Since this IFC model is IFC4, please use the modern conversion method instead.
curl --location --request POST 'https://developer.api.autodesk.com/modelderivative/v2/designdata/job' \
--header 'Authorization: Bearer ' \
--header 'Content-Type: application/json' \
--header 'x-ads-force: true' \
--data'{
"input": {
"urn": "{URN}"
},
"output": {
"formats": [
{
"type": "svf",
"views": [
"3d"
],
"advanced": {
"conversionMethod": "modern"
}
}
]
}
}'

Issue creating Storage Bucket in GCP using APIs

While following the Introduction to APIs in Google lab, I'm facing an issue while creating a storage bucket. I followed the instructions but still the following is shown:
Run the following command to create a Cloud Storage bucket:
curl -X POST --data-binary #values.json
-H "Authorization: Bearer $OAUTH2_TOKEN"
-H "Content-Type: application/json"
"https://www.googleapis.com/storage/v1/b?project=$PROJECT_ID"
Error:
{
"error": {
"code": 400,
"message": "Invalid bucket name: '\u003cqwiklabs-gcp-00-eb5dde0a1183-bucket'",
"errors": [
{
"message": "Invalid bucket name: '\u003cqwiklabs-gcp-00-eb5dde0a1183-bucket'",
"domain": "global",
"reason": "invalid"
}
]
}
}
1.Edit the values.json file
nano values.json
{ "name": "quicklab-test-your-bucket",
"location": "us",
"storageClass": "multi_regional"
}
2.Get the token:
gcloud auth print-access-token
3.Set the variables:
export OAUTH2_TOKEN=your-token
export PROJECT_ID=your-project-id
4.Create the bucket:
curl -X POST --data-binary #values.json \
-H "Authorization: Bearer $OAUTH2_TOKEN" \
-H "Content-Type: application/json" \
"https://www.googleapis.com/storage/v1/b?project=$PROJECT_ID"
5.You should receive similar output:
{
"kind": "storage#bucket",
"id": "qwiklabs-test-bucket",
"selfLink": "https://www.googleapis.com/storage/v1/b/sean123456789",
"projectNumber": "218136653205",
"name": "sean123456789",
"timeCreated": "2018-10-19T21:04:03.604Z",
"updated": "2018-10-19T21:04:03.604Z",
"metageneration": "1",
"location": "US",
"storageClass": "MULTI_REGIONAL",
"etag": "CAE="
}

Drive list files doesn't have nextPageToken when `fields` is present

When running this list files there is not a nextPageToken there is just files[].
curl \
'https://www.googleapis.com/drive/v3/files?fields=files(id%2C%20name)&key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
result:
{
"files": [
{
"id": "1",
"name": "1"
},
...
{
"id": "2",
"name": "2"
}
]
}
Leaving the fields parameter empty, the nextPageToken is returned.
curl \
'https://www.googleapis.com/drive/v3/files?key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
result:
{
"kind": "drive#fileList",
"nextPageToken": "~!!~AI9FV7TN...",
"incompleteSearch": false,
"files": [
{
"kind": "drive#file",
"id": "1",
"name": "1",
"mimeType": "application/vnd.google-apps.spreadsheet"
},
...
Is this a bug or is there some way to get the nextPageToken and limit the fields returned? The doc page for fields implies that it should work:
Note: The Drive API supports query parameters for data pagination (maxResults and nextPageToken). For APIs that support these parameters, use these parameters to reduce the results of each query to a manageable size. Otherwise, the performance gains possible with partial response might not be realized.
When fields=files(id,name) is used for the method of "Files: list", the file ID and filename are returned. In this case, the values of fields are files.id and files.name. nextPageToken is not included in fields. By this, the page token is not returned. When fields is not used, it seems that fields of nextPageToken,incompleteSearch,kind,files(id,name,kind,mimeType) is the default value. So I thought that this is not a bug, and it might be the current specification.
So when you want to retrieve nextPageToken when you use https://www.googleapis.com/drive/v3/files?fields=files(id%2C%20name), please include nextPageToken in fields as follows.
Modified curl command:
curl \
'https://www.googleapis.com/drive/v3/files?fields=nextPageToken%2Cfiles%28id%2Cname%29&key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
In this case, fields is nextPageToken,files(id,name).
Result:
When above curl command is run, the following result is returned.
{
"nextPageToken": "###",
"files": [
{"id": "###", "name": "###"},
{"id": "###", "name": "###"},
,
,
,
]
}
Reference:
Files: list

CURL keep throwing "Invalid body format"

so I have this body of a CURL:
-d '{
"documentType": "SQMProjectFact",
"status": "published",
"selectAttributes": [
"Supplier"
],
"filterExpressions": [
{
"name": "createdDateFrom",
"field": "TimeCreated",
"op": ">=",
"defaultValue": "2018-08-05T01:01:59Z
" },
{
"name": "createdDateTo",
"field": "TimeCreated",
"op": "<=",
"defaultValue": "2018-08-15T01:01:59Z"
}
]
}'
When I run it on postman, it works tottaly fine, but when I try to do it on CMD, it keeps throwing me "Invalid body format".
I research and try chagning ' for ", and " for \", and a lot of conmbinations of that, erasing the spaces (just to see if it that solved it), but it stills throwing me that error.
Just for info, these are the headers:
-H "Authorization: Bearer xXxXXXxx-xxXx-xxxx-xxxx-xxxxxxxxxxxx"
-H "Content-Type: application/json"
-H "accept: application/json"
-H "apiKey: xxxxxxxxxxxxxxxxxxxxx"
Thanks for those who will reply!

Github API v3 JSON passing

how can I avoid the parsing errors for
curl -H 'Accept: application/vnd.github.VERSION.raw' -XPUT -g 'https://api.github.com/repos/USER/l1/contents/PATH/FILENAME.json?ref=gh-pages&access_token=57eef6413b12cb439b837b8fc4751b3291650de1' -d '{
"message": "update from api",
"committer": {
"name": "USER",
"email": "USERe#MAIL.com"
},
"content": "[{"a": "aaa","b": "bbb"}]",
"sha": "c321fe9f6418053ecb87eb3cd2518a4xdfc83ebf"
}'
Answer:
{
"message": "**Problems parsing JSON**",
"documentation_url": "https://developer.github.com/v3/repos/contents/"
}
Instead of
"[{"a": "aaa","b": "bbb"}]"
I've tried
"[{\"a\": \"aaa",\"b\": \"bbb\"}]"
but then I get the following error:
{
"message": "**content is not valid Base64**",
"documentation_url": "https://developer.github.com/v3/repos/contents/"
}
Best,
If you open the URL to the documentation given in the error response, you'll see that the content needs to be Base64 encoded.