<?php

session_start();
require_once '../vendor/autoload.php';
$user_email = '';
$user_password = '';
$client_id = '';
$client_secret = '';
$redirect_uri = 'https://mysite.local/oauth_redirect';
$company_id = 45;
$environment = \Spredfast\CustomSolutions\Conversations\AnalyticsExportAPI::ENV_APP3;
$auth = new \Spredfast\CustomSolutions\OAuth\Example\ExampleAuth($user_email, $user_password, $client_id, $client_secret, $redirect_uri);
$access_token = $auth->getAccessToken();
if (!$access_token) {
    $access_token = $auth->authorize();
}
/**
 * Get last updated date
 */
$exporter = new \Spredfast\CustomSolutions\Conversations\AnalyticsExportAPI($auth, $company_id, $environment);
$last_updated_data = $exporter->lastUpdate();
/**
 * Show list of available reports
 */
$list = $exporter->reports();
foreach ($list as $report) {
    echo $report->title;
}
/**
 * Download report
 */
Exemplo n.º 2
0
/**
 * Use that if you want to authenticate a user via Spredfast OAuth on your site
 */
session_start();
require_once '../vendor/autoload.php';
$client_id = '';
$client_secret = '';
$redirect_uri = 'https://site.local/oauth_redirect';
/**
 * Login check. You don't need to set username and password so you could use empty strings for these params
 */
$auth = new \Spredfast\CustomSolutions\OAuth\Example\ExampleAuth('', '', $client_id, $client_secret, $redirect_uri);
$url = $auth->getLoginUrl();
echo '<a href="' . $url . '">login</a>';
// here you should redirect a user
//
/**
 * In another script you need to get a code and request an access token
 */
if (isset($_GET['code'])) {
    $code = $_GET['code'];
    $client = new \Spredfast\CustomSolutions\OAuth\Example\ExampleAuth('', '', $client_id, $client_secret, $redirect_uri);
    try {
        $access_token = $client->requestAccessToken($code);
    } catch (\Spredfast\CustomSolutions\OAuth\AuthException $e) {
        die("Can't get access token");
    }
} else {
    die('Code is required');
}