contextio / php-contextio-lite
该包已被废弃,不再维护。未建议替代包。
Context.IO Lite API 的 PHP 客户端库
1.5.1
2019-01-11 19:16 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2021-01-22 21:22:48 UTC
README
描述
Context.IO Lite 的 PHP 客户端库。
要求
PHP Curl (https://php.ac.cn/curl)
使用 Github 安装
将 class.contextio.php, class.contextioresponse.php 和 OAuth.php 复制到您的库目录中,然后在您的代码中添加 require_once '/class.contextio.php';
。
使用 Composer 安装
您可以通过将其添加到 composer.json 中的依赖项来安装库。
"require": { "contextio/php-contextio-lite": "1.3" }
示例
// include the lib include_once("class.contextio.php"); // define your API key and secret - find this https://console.context.io/#settings define('CONSUMER_KEY', 'YOUR API CONSUMER KEY'); define('CONSUMER_SECRET', 'YOUR API CONSUMER SECRET'); // instantiate the contextio object $contextio = new ContextIO(CONSUMER_KEY, CONSUMER_SECRET); // get a list of users and print the response data out $r = $contextio->listUsers(); print_r($r->getData()); // many calls are based for a User - you can define a USER_ID to make these calls // the USER_ID is returned in either the listUsers call or the getUser call // you can also get this from the interactive console define('USER_ID', 'A CONTEXTIO USER ID'); // You also need to know the EMAIL_ACCOUNT_LABEL and FOLDER to list messages. $r = $contextio->listEmailAccounts(USER_ID); print_r($r->getData()); // You can see all the folders in an email account using the listEmailAccountFolders method define('LABEL', 'AN EMAIL ACCOUNT LABEL'); $params = array('label'=>LABEL); $r = $contextio->listEmailAccountFolders(USER_ID, $params); print_r($r); // Now that you know the USER_ID, LABEL, and FOLDER you can list messages define('FOLDER', 'A FOLDER NAME'); $params = array('label'=>LABEL, 'folder'=>FOLDER); $r = $contextio->listMessages(USER_ID, $params); print_r($r); // It's a good idea to do error handling on your api calls. You can get the last error response // from the client, and then retry the call $x = 0; while($x < 10) { //retry the call up to 10 times if it fails $r = $contextio->listUsers(); if($r != false) { print_r($r->getData()); break; } else { print_r($contextio->getLastResponse()); $x++; sleep(5); //don't retry immediately } }
请参考 class.contextio.php 文件以查看所有方法的列表。