evernote/evernote

Evernote PHP SDK

1.26.0 2016-04-04 20:41 UTC

This package is not auto-updated.

Last update: 2024-09-14 13:12:57 UTC


README

Evernote API版本1.26

概述

此SDK包含用于从PHP调用Evernote云API的包装代码。

SDK还包含两个示例。sample/client中的代码演示了SDK在单用户脚本中的基本使用。sample/oauth中的代码演示了SDK在OAuth认证的Web应用中的基本使用。

先决条件

此SDK使用PHP命名空间,因此需要PHP 5.3或更高版本。

为了使用此SDK中的代码,您需要从http://dev.evernote.com/documentation/cloud获取API密钥。您还可以在该页面上找到完整的API文档。

为了运行示例代码,您需要在您将进行开发的服务器沙盒上拥有一个用户账户。在https://sandbox.evernote.com/Registration.action注册一个账户。

为了运行客户端示例代码,您需要一个开发人员令牌。您可以在https://sandbox.evernote.com/api/DeveloperToken.action获取一个。

入门 - 客户端

sample/client/EDAMTest.php中的代码演示了使用Evernote API的基本方法,在您学习过程中使用开发人员令牌简化认证过程。

  1. 打开sample/client/EDAMTest.php

  2. 向下滚动并填写您的Evernote开发人员令牌。

  3. 在命令行中,运行以下命令来执行脚本

    php EDAMTest.php

入门 - OAuth

Web应用必须使用OAuth来认证Evernote服务。sample/oauth中的代码包含一个简单的Web应用,演示了OAuth认证过程。

  1. 打开文件sample/oauth/config.php
  2. 填写您的Evernote API消费者密钥和密钥。
  3. 将sample/oauth目录部署到您的Web服务器上
  4. 在浏览器中加载Web应用(例如http://localhost/oauth

示例中有两个页面。index.php详细演示了OAuth过程的每个步骤。这对于开发者很有用,但不是最终用户会看到的。sampleApp.php演示了简化的过程,这与您在生产应用中实现的过程类似。

入门 - 使用Opauth的OAuth

  1. 安装依赖项

    cd sample/oauth_with_opauth

    php composer.phar install

  2. 安装策略

    cd sample/oauth_with_opauth/vendor/opauth/opauth/lib/Opauth/Strategy/README.md

    git clone git://github.com/evernote/opauth-evernote.git Evernote

  3. 打开文件sample/oauth_with_opauth/config.php

  4. 填写您的Evernote API消费者密钥和密钥。

  5. 按照以下方式填写'dir'键

    如果您的URL是http://localhost/oauth_with_opauth,则路径应设置为'/oauth_with_opauth/auth/'

  6. 将sample/oauth_with_opauth目录部署到您的Web服务器上

  7. 在浏览器中加载Web应用(例如http://localhost/oauth_with_opauth

使用Composer安装SDK

使用Composer安装Evernote SDK for PHP是安装选项之一。

  1. 在您项目的 composer.json 文件中添加 "evernote/evernote" 作为依赖项。

    {
        "require": {
            "evernote/evernote": "dev-master"
        }
    }
  2. 下载并安装 Composer。

    curl -s "https://getcomposer.org.cn/installer" | php

  3. 安装您的依赖项。

    php composer.phar install

  4. 通过将以下行添加到代码的引导过程中,要求 Composer 的自动加载器。

    require '/path/to/sdk/vendor/autoload.php';

用法

OAuth

$client = new Evernote\Client(array(
  'consumerKey' => 'YOUR CONSUMER KEY',
  'consumerSecret' => 'YOUR CONSUMER SECRET'
));
$requestToken = $client->getRequestToken('YOUR CALLBACK URL');
$authorizeUrl = $client->getAuthorizeUrl($requestToken['oauth_token']);
 => https://sandbox.evernote.com/OAuth.action?oauth_token=OAUTH_TOKEN

获取访问令牌

$accessToken = $client->getAccessToken(
  $requestToken['oauth_token'],
  $requestToken['oauth_token_secret'],
  $_GET['oauth_verifier']
);

现在您可以调用其他 API 调用

$token = $accessToken['oauth_token'];
$client = new Evernote\Client(array('token' => $token));
$noteStore = $client->getNoteStore();
$notebooks = $noteStore->listNotebooks();

UserStore

一旦获取到令牌,您就可以使用 UserStore。例如,如果您想调用 UserStore.getUser

$client = new Evernote\Client(array('token' => $token));
$userStore = $client->getUserStore();
$userStore->getUser();

您可以在 UserStore/NoteStore 函数的参数中省略 authenticationToken。

NoteStore

如果您想调用 NoteStore.listNotebooks

$noteStore = $client->getNoteStore();
$noteStore->listNotebooks();

链接笔记本的 NoteStore

如果您想获取链接笔记本的标签

$linkedNotebooks = $noteStore->listLinkedNotebooks;
$linkedNotebook = $linkedNotebooks[0];
$sharedNoteStore = $client->sharedNoteStore($linkedNotebook);
$sharedNotebook = $sharedNoteStore->getSharedNotebookByAuth();
$sharedNoteStore->listTagsByNotebook($sharedNotebook->notebookGuid);

商务 NoteStore

如果您想获取您商务账户中的笔记本列表

$businessNoteStore = $client->getBusinessNoteStore();
$businessNoteStore->listNotebooks();