You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into something that's either a bug or a missing feature (depending on your point of view). Would it be possible to add support for Google's batch requests (https://developers.google.com/gmail/api/guides/batch) to the built-in google classes (Keyring_Service_GoogleMail, etc.)
The problem I ran into was, I was trying to use Google's batch mode with code that looked something like this (pseudo code)
The issue I ran into is the request method would return a null value, but there wouldn't be an error otherwise. It seemed as though the HTTP request was succeeding. After digging into the issue a bit, I believe the culprit is this bit of code in the base OAuth class.
#File: wp-content/plugins/keyring/includes/services/core/oauth2.php/** * OAuth2 implementations generally use JSON. You can still override this * per service if you like, but by default we'll assume JSON. */functionparse_response( $response ) {
returnjson_decode( $response );
}
The base OAuth2 class appears to assume the response will be a JSON formatted string. However, in the base of Google's batch API, the response is a multipart message. The json_decode function fails to parse this, returning NULL.
I realize there's workarounds -- implement my own service class that extends Keyring_Service_GoogleMail and include a multipart aware parse_response method, or add a filter/listener for the http_response filter and parse the response myself -- however it feels like this is something these classes should be able to handle themselves, or at minimum come back with an error that indicated the response could not be parsed.
The text was updated successfully, but these errors were encountered:
Just some additional datapoint -- as much for the Google searches as anything.
A colleague (hat tip @rowasc) pointed out that the oAuth2 request method has two undocumented params -- full_response and raw_response that allow us to make requests without the automatic attempt as a json_decode, and are suitable workarounds.
That said -- it still seems like the Google service classes could/should be aware of the multipart Content-Type and do something smarter than return an empty error.
I ran into something that's either a bug or a missing feature (depending on your point of view). Would it be possible to add support for Google's batch requests (https://developers.google.com/gmail/api/guides/batch) to the built-in google classes (
Keyring_Service_GoogleMail
, etc.)The problem I ran into was, I was trying to use Google's batch mode with code that looked something like this (pseudo code)
The issue I ran into is the
request
method would return anull
value, but there wouldn't be an error otherwise. It seemed as though the HTTP request was succeeding. After digging into the issue a bit, I believe the culprit is this bit of code in the base OAuth class.The base OAuth2 class appears to assume the response will be a JSON formatted string. However, in the base of Google's batch API, the response is a multipart message. The
json_decode
function fails to parse this, returningNULL
.I realize there's workarounds -- implement my own service class that extends
Keyring_Service_GoogleMail
and include a multipart awareparse_response
method, or add a filter/listener for thehttp_response
filter and parse the response myself -- however it feels like this is something these classes should be able to handle themselves, or at minimum come back with an error that indicated the response could not be parsed.The text was updated successfully, but these errors were encountered: