コード例 #1
0
 public function disconnect($deleteObj)
 {
     $response = $this->defaultResponseObj;
     $userId = parent::getUserId();
     if ($userId == false) {
         return "Invalid User";
     }
     $contextio = new ContextIO(CONTEXTIO_KEY, CONTEXTIO_SECRET);
     $apiResponse = $contextio->deleteUser($deleteObj["contextio_id"]);
     if ($apiResponse == false) {
         // Failed to delete the account
         $response["Message"] = "Account not found. Contact us for additional assistance.";
     } else {
         $rawResponse = $apiResponse->getRawResponse();
         $rawResponse = json_encode($rawResponse, true);
         if (property_exists($rawResponse, "error") && $rawResponse["error"] != "") {
             // Failed to delete the account
             $response["Message"] = "Unable to unlink account at this time. Try again later or contact us for additional assistance.";
             $response["ApiResponse"] = $apiResponse->getRawResponse();
         } else {
             // Deleted account, delete reference from our database
             $sth = $this->db->prepare("DELETE FROM EmailAccounts WHERE Contextio_Id = :id LIMIT 1");
             $sth->execute(array(":id" => $deleteObj["contextio_id"]));
             $response["Success"] = true;
             $response["Message"] = "Account has been successfully unlinked.";
         }
     }
     return $response;
 }
コード例 #2
0
$database_name = 'schedule-ninja';
$database_info = 'mysql:host=' . $database_host . ';dbname=' . $database_name;
try {
    $PDO = new PDO($database_info, $database_username, $database_password);
    $PDO->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
    $PDO->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
} catch (PDOException $e) {
    echo $e->getMessage();
    exit;
}
// Include the functions
require '/var/www/html/includes/functions.php';
require '/var/www/html/includes/calendar.php';
require '/var/www/html/includes/handle_sendgrid.php';
require_once '/var/www/html/php-libraries/contextio/class.contextio.php';
$contextIO = new ContextIO(getenv('CONTEXTIO_KEY'), getenv('CONTEXTIO_SECRET'));
$accountId = null;
$r = $contextIO->listAccounts();
foreach ($r->getData() as $account) {
    echo 'Scraping ' . $account['id'] . "\t" . join(", ", $account['email_addresses']) . PHP_EOL;
    if (is_null($accountId)) {
        $accountId = $account['id'];
    }
}
$contextIO->syncSource($accountId);
$r = $contextIO->listMessages($accountId, array('include_body' => true));
foreach ($r->getData() as $message) {
    $msg_id = $message['message_id'];
    $subject = $message['subject'];
    $date_received = date("Y-m-d H:i:s", $message['date_received']);
    $recipient = $message['addresses']['to'][0]['email'];
コード例 #3
0
#!/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' => '*****@*****.**', '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' => '*****@*****.**', 'limit' => 2);