我遇到了Context.io API的问题。我不断收到以下错误消息:
Warning: Invalid argument supplied for foreach() in /usr/share/nginx/html/custom-assets/includes/ContextIO/demo.php on line 11
这是我的php代码:
// Require the Context.io PHP Library
require('class.contextio.php');
// See https://console.context.io/#settings to get your consumer key and consumer secret.
$contextIO = new ContextIO('consumer key','consumer secret');
$accountId = 'xxxxxxxxxx'; // Account ID of email account
$args = array('folder' => 'Inbox', 'include_flags' => 1, 'include_thread_size' => 1, 'include_body' => 1, 'limit' => 50);
echo "Getting last 50 messages...<br><br>";
$r = $contextIO->listMessages($accountId, $args);
if ($r !== false) {
foreach ($r->getData() as $message) {
echo "Subject: ".$message['subject']."<br>";
}
} else {
var_dump($r);
}
我不知道为什么这不起作用。有人知道为什么?
答案 0 :(得分:0)
ContextIO库中的所有函数都返回ContextIOResponse对象,如果API返回http错误代码,则返回false。如果您在致电if($r !== false)
之前添加getData()
支票,则应该收到任何错误。