Skip to content

Latest commit

 

History

History
149 lines (93 loc) · 3.61 KB

Getting_Started.md

File metadata and controls

149 lines (93 loc) · 3.61 KB

Installation

The recommended way to install the SDK is through composer.

Just run these two commands to install it:

$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar require evernote/evernote-cloud-sdk-php dev-master

Now you can add the autoloader, and you will have access to the library:

<?php

require 'vendor/autoload.php';

If you don't use Composer , just require the provided autoloader:

<?php

require 'src/autoload.php';

Getting an OAuth token

The OAuth process does not require the php-oauth extension. The only requirement is to have sessions enabled to keep data during the oauth process.

<?php
require 'vendor/autoload.php';

//set this to false to use in production
$sandbox = true;

$oauth_handler = new \Evernote\Auth\OauthHandler($sandbox);

$key      = '%key%';
$secret   = '%secret%';
$callback = 'http://host/pathto/evernote-cloud-sdk-php/sample/oauth/index.php';

$oauth_data  = $oauth_handler->authorize($key, $secret, $callback);

echo "\nOauth Token : " . $oauth_data['oauth_token'];

You can then instantiate the client and call the api with this token.

Getting the "simple" client

The "simple" client is a high-level wrapper on top of the "advanced" client (see below). It provides helper methods that hide complex stuff such as dealing with business accounts, app notebooks, etc.

All API calls are made with the \Evernote\Client. Instantiate a new client object with a token and you're done. The token can be an oauth token or a dev token.

<?php

require_once 'vendor/autoload.php';

$token = '%oauth_token%';

$sandbox = true;

$client = new \Evernote\Client($token, $sandbox);

Getting the "advanced" client

The advanced client gives you a low level access to the API. That means you can call the thrift methods directly. See the API Reference for the list of methods available. You can use this client for optimization reasons or to achieve more complex tasks than the ones handled by the simple client.

There are two ways to get the advanced client.

From scratch :

<?php

require_once 'vendor/autoload.php';

$token = '%oauth_token%';

$sandbox = true;

$advancedClient = new \Evernote\AdvancedClient($token, $sandbox);

or, if you already have an instance of the simple client :

<?php

require_once 'vendor/autoload.php';

$token = '%oauth_token%';

$sandbox = true;

$client = new \Evernote\Client($token, $sandbox);

$client->getNote('the-note-guid');

$advancedClient = $client->getAdvancedClient();

Once you have a instance of the advanced client you can, for example, call the getUser() method:

// First, get the right Store
$userStore = $advancedClient->getUserStore();

// Then do the call
$user = $userStore->getUser();

You may notice that we don't pass the token to the getUser() method. It's the same with all the methods that require a token. Just omit it as it is already set on the client object.

Using the "simple" client

Create a note

Delete a note

Move a note

Share a note

Replace a note

Add resources to a note

Find notes

Manage reminders

Going further

The 'sample' folder contains a few code samples to help you get started with basic features.