亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHP 相當于 Python 的 oauth2client 對 Google 提醒的 POST 請求

PHP 相當于 Python 的 oauth2client 對 Google 提醒的 POST 請求

PHP
冉冉說 2022-06-17 14:19:58
我想將這個用于 Google 提醒的開源 Python 庫移植到 PHP:https://github.com/jonahar/google-reminders-cli我已經在https://developers.google.com/identity/protocols/OAuth2WebServer的幫助下移植了授權我的 PHP 版本:https ://github.com/Jinjinov/google-reminders-php現在我需要移植 Python 的 oauth2client POST 請求: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,    )使用https://github.com/googleapis/google-api-php-client進行授權我的 Guzzle 客戶端 POST 請求返回 HTTP 400 - 錯誤請求 - 即使 Python 版本運行正常。我用了:http://docs.guzzlephp.org/en/stable/request-options.html#headershttp://docs.guzzlephp.org/en/stable/request-options.html#body我的代碼(帶有授權和 $httpClient 的完整代碼在 GitHub 上):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' => [ 'content-type' => 'application/json' ],            '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;    }}
查看完整描述

1 回答

?
楊魅力

TA貢獻1811條經驗 獲得超6個贊

感謝 04FS 的解決方案('content-type'應該是'application/json+protobuf')


如果其他人有興趣:


function list_reminders($httpClient, $num_reminders) {

    /*

    returns a list of the last num_reminders created reminders, or

    None if an error occurred

    */


    $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' => [ 'content-type' => 'application/json+protobuf' ],

            'body' => json_encode($body)

        ]

    );

    if ($response->getStatusCode() == 200) {

        $content = $response->getBody();

        $content_dict = json_decode($content, true);

        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;

    }

}


查看完整回答
反對 回復 2022-06-17
  • 1 回答
  • 0 關注
  • 115 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號