PHP code example of lanlin / nylas-php

1. Go to this page and download the library: Download lanlin/nylas-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lanlin / nylas-php example snippets


use Nylas\Client;

$options =
[
    'client_id'        => 'your client id',    //       => true,
    'region'           => 'oregon', // server region, can be oregon of United States, ireland of Europe, default is oregon
    'log_file'         => dirname(__FILE__) . '/test.log',  // a file path or a resource handler
    'access_token'     => 'your access token',
];

$nylas = new Client($options);

$nylas->Options->setXxx();

$id  = 'id_xxx';
$ids = ['id_xxx', 'id_yyy', ...];

// one per time
$dataA = $nylas->Contacts->Contact->returnAContact($id);
$dataB = $nylas->Contacts->Contact->deleteAContact($id);

// batch request
$dataC = $nylas->Contacts->Contact->returnAContact($ids);
$dataD = $nylas->Contacts->Contact->deleteAContact($ids);

$params =
[
    'state'        => 'testing',
    'login_hint'   => '[email protected]',
    'redirect_uri' => 'https://www.test.com/redirect_callback',
];

// generate the url that your user need be redirect to.
$url = $nylas->Authentication->Hosted->authenticateUser($params);

$data = $nylas->Authentication->Hosted->sendAuthorizationCode($params);

// save your token some where
// or update the client option
$nylas->Options->setAccessToken("pass the token you got");

   [
       'httpStatus'  => 'http status code',
       'invalidJson' => true,
       'contentType' => 'response header content type',
       'contentBody' => 'response body content',
   ]
   

   [
       // ...
       [
           'error'     => true,
           'code'      => 'exception code',
           'message'   => 'exception message',
           'exception' => 'exception instance',
       ],
       // ...
   ]
   

   $handler = fopen('php://temp', 'w+');

   $options =
   [
       'log_file' => $handler,
       ...
   ];

   $nylas = new Client($options);
   $nylas->doSomething();
   ....

   rewind($handler);
   $logContent = stream_get_contents($handler);
   fclose($handler);

   $yourPsrLogger->debug($logContent);
   

$nylas->Management->Account->xxx();
$nylas->Management->Application->xxx();
shell
composer