第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

PHP 相當(dāng)于 Python 的 oauth2client 對 Google 提醒的 POST 請求

PHP 相當(dāng)于 Python 的 oauth2client 對 Google 提醒的 POST 請求

PHP
冉冉說 2022-06-17 14:19:58
我想將這個用于 Google 提醒的開源 Python 庫移植到 PHP:https://github.com/jonahar/google-reminders-cli我已經(jīng)在https://developers.google.com/identity/protocols/OAuth2WebServer的幫助下移植了授權(quán)我的 PHP 版本:https ://github.com/Jinjinov/google-reminders-php現(xiàn)在我需要移植 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進(jìn)行授權(quán)我的 Guzzle 客戶端 POST 請求返回 HTTP 400 - 錯誤請求 - 即使 Python 版本運(yùn)行正常。我用了:http://docs.guzzlephp.org/en/stable/request-options.html#headershttp://docs.guzzlephp.org/en/stable/request-options.html#body我的代碼(帶有授權(quán)和 $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貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超6個贊

感謝 04FS 的解決方案('content-type'應(yīng)該是'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;

    }

}


查看完整回答
反對 回復(fù) 2022-06-17
  • 1 回答
  • 0 關(guān)注
  • 110 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號