ETag not updated in PATCH response - google-drive-api

I'm testing my application that uses Drive API v2, and I noticed that I'm not
getting a new ETag in the response of a PATCH request.
I made some tests using the Google APIs Explorer. This is the PATCH request:
PATCH https://www.googleapis.com/drive/v2/files/0B-TenPiSMBplMTJnVlYxTEEwQ28?key={YOUR_API_KEY}
Content-Type: application/json
Authorization: Bearer ...
X-JavaScript-User-Agent: Google APIs Explorer
{
"title": "file.tmp"
}
And this is the beginning of the PATCH response that shows the ETag "EBHN0a_u6Vh64YcTBDNdNyfF7Hs/MTM4MTI2MTIxODY0MQ":
200 OK
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Encoding: gzip
Content-Length: 1019
Content-Type: application/json; charset=UTF-8
Date: Tue, 08 Oct 2013 19:46:36 GMT
Etag: "EBHN0a_u6Vh64YcTBDNdNyfF7Hs/MTM4MTI2MTIxODY0MQ"
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Pragma: no-cache
Server: GSE
{
"kind": "drive#file",
"id": "0B-TenPiSMBplMTJnVlYxTEEwQ28",
"etag": "\"EBHN0a_u6Vh64YcTBDNdNyfF7Hs/MTM4MTI2MTIxODY0MQ\"",
"selfLink": "https://content.googleapis.com/drive/v2/files/0B-TenPiSMBplMTJnVlYxTEEwQ28",
"webContentLink": "https://docs.google.com/uc?id=0B-TenPiSMBplMTJnVlYxTEEwQ28&export=download",
"alternateLink": "https://docs.google.com/file/d/0B-TenPiSMBplMTJnVlYxTEEwQ28/edit?usp=drivesdk",
"iconLink": "https://ssl.gstatic.com/docs/doclist/images/icon_10_generic_list.png",
"title": "file.tmp",
But if I do a GET request just after the PATCH:
GET https://www.googleapis.com/drive/v2/files/0B-TenPiSMBplMTJnVlYxTEEwQ28?key={YOUR_API_KEY}
Authorization: Bearer ...
X-JavaScript-User-Agent: Google APIs Explorer
In the response, I get an updated ETag ("EBHN0a_u6Vh64YcTBDNdNyfF7Hs/MTM4MTI2MTU5NjAyNg"):
200 OK
Cache-Control: private, max-age=0, must-revalidate, no-transform
Content-Encoding: gzip
Content-Length: 1021
Content-Type: application/json; charset=UTF-8
Date: Tue, 08 Oct 2013 19:48:44 GMT
Etag: "EBHN0a_u6Vh64YcTBDNdNyfF7Hs/MTM4MTI2MTU5NjAyNg"
Expires: Tue, 08 Oct 2013 19:48:44 GMT
Server: GSE
{
"kind": "drive#file",
"id": "0B-TenPiSMBplMTJnVlYxTEEwQ28",
"etag": "\"EBHN0a_u6Vh64YcTBDNdNyfF7Hs/MTM4MTI2MTU5NjAyNg\"",
"selfLink": "https://content.googleapis.com/drive/v2/files/0B-TenPiSMBplMTJnVlYxTEEwQ28",
"webContentLink": "https://docs.google.com/uc?id=0B-TenPiSMBplMTJnVlYxTEEwQ28&export=download",
"alternateLink": "https://docs.google.com/file/d/0B-TenPiSMBplMTJnVlYxTEEwQ28/edit?usp=drivesdk",
"iconLink": "https://ssl.gstatic.com/docs/doclist/images/icon_10_generic_list.png",
"title": "file.tmp",
Is this the intended behavior? I was expecting to get the updated ETag in the
PATCH response to avoid another roundtrip to the server. Notice also that I
experienced the same behavior using PUT instead of PATCH.

Sadly, Drive is somewhat asynchronous under the hood. Stuff like etags and some URLs are populated asynchronously after your PATCH has completed.

Related

Account linking error: "Can't parse the response. The response needs to be JSON format."

I am attempting account linking within 'Actions on Google'. Everything works until my OAuth provider responds to Google's request for tokens.
This is the JSON that is returned and appears to be properly formatted:
{"access_token":"edeaa27e-12b7-43a1-bc7c-e6bbf9af71c3","expires_in":5184000.0,"refresh_token":"4344383b-cf07-4d12-a5c2-44b6481f5f48","token_type":"Bearer"}
This is the error:
{ "#type": "type.googleapis.com/google.identity.accountlinking.type.AccountLinkingError", "errorReason": "Can't parse the response. The response needs to be JSON format.", "response": { ... }, "step": "AUTH_CODE_EXCHANGE" }
Details:
{
"insertId": "-hgv4mfb4b",
"jsonPayload": {
"#type": "type.googleapis.com/google.identity.accountlinking.type.AccountLinkingError",
"errorReason": "Can't parse the response. The response needs to be JSON format.",
"response": {
"status": 200,
"body": "{\"access_token\":\"cdd79134-316d-46ca-8d82-62fc7c35d905\",\"expires_in\":5184000.0,\"refresh_token\":\"fc63ceb3-0a8d-40ac-a1a3-a8cfab110bef\",\"token_type\":\"Bearer\"}"
},
"step": "AUTH_CODE_EXCHANGE"
},
"resource": {
"type": "assistant_action_project",
"labels": {
"project_id": "my-project"
}
},
"timestamp": "2021-07-30T23:15:28.221Z",
"severity": "ERROR",
"logName": "projects/my-project/logs/accountlinking-pa.googleapis.com%2Ferror",
"receiveTimestamp": "2021-07-30T23:15:28.676796217Z"
}
Here is the response from my OAuth provider via curl. This is what Google gets. It looks like properly formatted JSON.
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Cache-Control: private
Cache-Control: private
< Content-Type: application/json; charset=utf-8
Content-Type: application/json; charset=utf-8
< Vary: Accept
Vary: Accept
< Server: Microsoft-IIS/8.5
Server: Microsoft-IIS/8.5
< Request-Context: appId=cid-v1:f494398c-ac65-47c8-84be-65aea2c190a4
Request-Context: appId=cid-v1:f494398c-ac65-47c8-84be-65aea2c190a4
< X-HOST-nonce: 3eTaf/2/7riVVh24uAsUT+KHqcJPq0F2cw7C5ldMkMF4iH5rDbHQEgOp2OU9RaQFr/HjBBEpkKekcCxlmzek5g==
X-HOST-nonce: 3eTaf/2/7riVVh24uAsUT+KHqcJPq0F2cw7C5ldMkMF4iH5rDbHQEgOp2OU9RaQFr/HjBBEpkKekcCxlmzek5g==
< X-Powered-By: ServiceStack/4.040 Win32NT/.NET
X-Powered-By: ServiceStack/4.040 Win32NT/.NET
< X-AspNet-Version: 4.0.30319
X-AspNet-Version: 4.0.30319
< X-Powered-By: ASP.NET
X-Powered-By: ASP.NET
< Date: Tue, 03 Aug 2021 03:17:00 GMT
Date: Tue, 03 Aug 2021 03:17:00 GMT
< Content-Length: 155
Content-Length: 155
< x-HOST-proxy: true
x-HOST-proxy: true
< Strict-Transport-Security: max-age=15768000
Strict-Transport-Security: max-age=15768000
{"access_token":"6cff16ee-3b3e-4ecf-9664-51515ede6cc8","expires_in":5184000.0,"refresh_token":"03725df6-8d4c-434a-ab36-adedb43b76d7","token_type":"Bearer"}
Google will not accept the 'expires_in' value above, because it includes a decimal. Not sure if this impacts all values with a decimal or just '.0', but the OAuth spec doesn't seem to specifically exclude such a value. Javascript converts any float with just a 0 after the decimal to a whole number. My issue was that the 3rd party OAuth provider was returning a string including a float that Google would not parse as JSON.

No enterprise was found for the given id

I have a valid Organization created at https://play.google.com/work. When I use the Organization ID available here as Enterprise Id for API calls avaialbe at https://developers.google.com/apis-explorer/#p/androidenterprise/v1/ , I am always getting below response.
404
cache-control: private, max-age=0 content-encoding: gzip content-length: 175 content-type: application/json; charset=UTF-8 date: Mon, 17 Jun 2019 07:47:15 GMT expires: Mon, 17 Jun 2019 07:47:15 GMT server: GSE vary: Origin, X-Origin
{ "error": { "errors": [ { "domain": "global", "reason": "notFound", "message": "No enterprise was found for the given id.", "locationType": "parameter", "location": "enterpriseId" } ], "code": 404, "message": "No enterprise was found for the given id." } }
Note: OAuth 2.0 Authorization is on.
This error could arise when the enterprise has already been deleted from Google console (https://play.google.com/work). You can navigate to above URL and in admin settings you can view your enterprise.

Orion CB: Can't Access Entities via /v2/entities endpoint

While creating a wirecloud wiring using NGSI Source operator, I encountered an error (helpless error) for couple of days, regarding connection to my instance of Orion CB. I can confirm all other NGSI operator settings entered are correct.
Error creating subscription in the context broker server: Connection Error
I however, suspect this error has to do with Orion NOT finding the entities to subscribe the NGSI Source operator. This is because I tried accessing Eindhoven's broker (http://212.159.228.70:1026/) and it works, NGSI Source operator subscription created successfully.
Equally, I get all entities/attributes in the Eindhoven's broker using:
Akil$http http://212.159.228.70:1026/v2/entities
HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Length: 15501
Content-Type: application/json
Date: Mon, 13 May 2019 10:20:20 GMT
Fiware-Correlator: b5e5294a-7568-11e9-83c8-0242ac120003
[
{
"NO2": {
"metadata": {},
"type": "Number",
"value": 27.5
},
"Ozon": {
"metadata": {},
"type": "Number",
"value": 59.5
},
"PM1": {
"metadata": {},
"type": "Number",
"value": 8
},
"PM10": {
"metadata": {},
"type": "Number",
"value": 12
},
.
.
}
]
But then I cannot get the entities in my Orion instance using same scenario:
Akil$ http 193.136.xx.xx:53154/v2/entities
HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Length: 2
Content-Type: application/json
Date: Mon, 13 May 2019 10:36:13 GMT
Fiware-Correlator: ee22e4b2-756a-11e9-afa1-0242ac160007
[]
Return empty list, whereas I have available 2 FIWARE services: environment and urbansense. The entities I want to access are available with the urbansense fiware-service having /basic fiware-servicepath.
Service health:
Akil$ http 193.136.xx.xx:53154/version
HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Length: 345
Content-Type: application/json
Date: Mon, 13 May 2019 10:50:13 GMT
Fiware-Correlator: e32bf3da-756c-11e9-9371-0242ac160007
{
"orion": {
"compile_time": "Tue Feb 12 10:51:10 UTC 2019",
"compiled_by": "root",
"compiled_in": "4f8128ac7b5b",
"doc": "https://fiware-orion.rtfd.io/",
"git_hash": "7ae8c69b97cd875236b952322a6bd503debbd13d",
"release_date": "Tue Feb 12 10:51:10 UTC 2019",
"uptime": "6 d, 18 h, 7 m, 6 s",
"version": "2.1.0-next"
}
}
Questions:
Why can't I access my Orion instance same way I accessed Eindhoven's
broker?
Is this the reason why my wiring for NGSI Source operator
failed, thus reporting subscription error above?
I'm not sure of fully understading your case (specially the relationship with Wirecloud, as I'm not an expert in Wirecloud), but let's try to answer... :)
From:
[GET /v2/entities] Return empty list, whereas I have available 2 FIWARE services: environment and urbansense. The entities I want to access are available with the urbansense fiware-service having /basic fiware-servicepath.
If the entities you want to access are available in a given service and subservice, then you should add then to the GET request. I don't know how the http command works, but if it were curl it would be something like this
curl -H 'fiware-service: environment' and -H 'fiware-servicepath: /basic' http://212.159.228.70:1026/v2/entities

500 Internal Errors using Google's URL shortener service API

I'm trying to complete the JavaScript track on Codecademy, which requires an api key to access Google's URL shortener service. When I try to shorten, whether there or even when using the API's explorer page, I get errors.
POST https://www.googleapis.com/urlshortener/v1/url?key={YOUR_API_KEY}
{
"longUrl": "https://freecodecamp.org"
}
500 Internal Server Error
cache-control: private, max-age=0
content-encoding: gzip
content-length: 122
content-type: application/json; charset=UTF-8
date: Tue, 02 Jan 2018 18:13:54 GMT
expires: Tue, 02 Jan 2018 18:13:54 GMT
server: GSE
vary: Origin, X-Origin
{
"error": {
"errors": [
{
"domain": "global",
"reason": "backendError",
"message": "Backend Error"
}
],
"code": 500,
"message": "Backend Error"
}
}
Yeah... we're getting that too...
I believe Google Shortening service is currently down...

WebApi with Odata NextPage and Count not appearing in the JSON response

I have a webapi method that I want to switch oData paging etc on.
I followed the example in http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/supporting-odata-query-options
My method looks like:
public PageResult<UserViewModel> GetUsers(ODataQueryOptions<UserViewModel> options)
{
var settings = new ODataQuerySettings()
{
PageSize = 2
};
var results = UserLogic.GetUsers(userId, UserManager, _db);
var filtered = options.ApplyTo(results, settings);
var pagedResult = new PageResult<UserViewModel>(
filtered as IEnumerable<UserViewModel>,
Request.GetNextPageLink(),
Request.GetInlineCount());
return pagedResult;
}
That the count is populated and the next page link is there and the correct oData options are applied i.e. sort order etc. When I return it in my api method, the correct data comes back, but the count and next link don't appear in my json.
Am I missing a setting to turn this on?
i.e. this is my json response:
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
X-RequestID: b215962b-6a4a-431d-9850-7ecbf808538e
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcUmVwb3NpdG9yaWVzXEdpdEh1YlxxbGRyYS1wb3J0YWxccWxkcmEtcG9ydGFsLldlYlxxbGRyYS5iYXNlbGluZS5hcGlcYXBpXHVzZXJz?=
X-Powered-By: ASP.NET
Date: Fri, 04 Apr 2014 05:16:53 GMT
Content-Length: 554
[
{
"Id": "500e6f96-b2bd-48d9-8181-5bbc39c673f6",
"UserName": "adam#test.com",
"Organisation": {
"Id": "f179bc35-89b8-e311-9dfd-0050569b4cee",
"Name": "Black and White Cabs Pty Ltd",
"IsActive": true,
"LastUpdatedDate": "2014-04-03T11:35:26.167"
},
"IsLockedOut": false,
"Roles": []
},
{
"Id": "0d661d1b-9e52-4f2f-baec-3eb89197bb6d",
"UserName": "bob#test.com",
"Organisation": null,
"IsLockedOut": false,
"Roles": [
"Service Administrator"
]
}
]
This should work.
Be sure to remove the [EnableQuery] attribute if it is being applied to your method or controller. This will cause the returned JSON to not include the count and next link.