-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathexamples.php
More file actions
65 lines (55 loc) · 2.26 KB
/
examples.php
File metadata and controls
65 lines (55 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/php
<?php
// remove first line above if you're not running these examples through PHP CLI
include_once("class.contextio.php");
// see https://console.context.io/#settings to get your consumer key and consumer secret.
$contextIO = new ContextIO('consumerKeyHere','consumerSecretHere');
$accountId = null;
// list your accounts
$r = $contextIO->listAccounts();
foreach ($r->getData() as $account) {
echo $account['id'] . "\t" . join(", ", $account['email_addresses']) . "\n";
if (is_null($accountId)) {
$accountId = $account['id'];
}
}
if (is_null($accountId)) {
die;
}
// EXAMPLE 1
// Print the subject line of the last 20 emails sent to with bill@widgets.com
$args = array('to'=>'bill@widgets.com', 'limit'=>20);
echo "\nGetting last 20 messages exchanged with {$args['to']}\n";
$r = $contextIO->listMessages($accountId, $args);
foreach ($r->getData() as $message) {
echo "Subject: ".$message['subject']."\n";
}
// EXAMPLE 2
// Download all versions of the last 2 attachments exchanged with bill@widgets.com
$saveToDir = dirname(__FILE__)."/".mt_rand(100,999);
mkdir($saveToDir);
$args = array('email'=>'bill@widgets.com', 'limit'=>2);
echo "\nObtaining list of last two attachments exchanged with {$args['email']}\n";
$r = $contextIO->listFiles($accountId, $args);
foreach ($r->getData() as $document) {
echo "\nDownloading all versions of document \"".$document['file_name']."\"\n";
foreach ($document['occurrences'] as $attachment) {
echo "Downloading attachment '".$attachment['file_name']."' to $saveToDir ... ";
$contextIO->getFileContent($accountId, array('file_id'=>$attachment['fileId']), $saveToDir."/".$attachment['file_name']);
echo "done\n";
}
}
// EXAMPLE 3
// Download all attachments with a file name that contains the word 'proposal'
$saveToDir = dirname(__FILE__)."/".mt_rand(100,999);
mkdir($saveToDir);
echo "\nDownloading all attachments matching 'creenshot'\n";
$args = array('file_name'=>'creenshot');
$r = $contextIO->listFiles($accountId, $args);
foreach ($r->getData() as $attachment) {
echo "Downloading attachment '".$attachment['file_name']."' to $saveToDir ... ";
$contextIO->getFileContent($accountId, array('file_id'=>$attachment['file_id']), $saveToDir."/".$attachment['file_name']);
echo "done\n";
}
echo "\nall examples finished\n";
?>