I would like to port this open source Python library for Google Reminders to PHP:
https://github.com/jonahar/google-reminders-cli
I have ported the authorization with the help of https://developers.google.com/identity/protocols/OAuth2WebServer
My PHP version: https://github.com/Jinjinov/google-reminders-php
Now I need to port the Python's oauth2client POST request:
body = {
'5': 1, # boolean field: 0 or 1. 0 doesn't work ¯\_(ツ)_/¯
'6': num_reminders, # number number of reminders to retrieve
}
HEADERS = {
'content-type': 'application/json+protobuf',
}
response, content = self.auth_http.request(
uri='https://reminders-pa.clients6.google.com/v1internalOP/reminders/list',
method='POST',
body=json.dumps(body),
headers=HEADERS,
)
My $httpClient POST request returns HTTP 404 - Not Found - even though the Python version is working OK.
authorization is made with https://github.com/googleapis/google-api-php-client
$httpClient is Guzzle Client - http://docs.guzzlephp.org/en/stable/
specifially I used:
- http://docs.guzzlephp.org/en/stable/request-options.html#headers
- http://docs.guzzlephp.org/en/stable/request-options.html#body
My code (full code with authorization and $httpClient is on GitHub):
$HEADERS = [
'content-type' => 'application/json',
];
function list_reminders($httpClient, $num_reminders) {
$body = (object)[
'5' => 1, // boolean field: 0 or 1. 0 doesn't work ¯\_(ツ)_/¯
'6' => $num_reminders, // number of reminders to retrieve
];
$response = $httpClient->request(
'POST',
'https://reminders-pa.clients6.google.com/v1internalOP/reminders/list',
[
'headers' => $HEADERS,
'body' => json_encode($body)
]
);
if ($response->getStatusCode() == $HTTP_OK) {
$content = $response->getBody();
$content_dict = json_decode($content);
if (!array_key_exists('1', $content_dict)) {
return [];
}
$reminders_dict_list = $content_dict['1'];
$reminders = [];
foreach($reminders_dict_list as $reminder_dict) {
array_push($reminders, build_reminder($reminder_dict));
}
return $reminders;
}
else {
return null;
}
}
from PHP equivalent of Python's oauth2client POST request to Google Reminders
No comments:
Post a Comment