php [evernote php] evernote api https://github.com/evernote/evernote-cloud-sdk-php #note

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php [evernote php] evernote api https://github.com/evernote/evernote-cloud-sdk-php #note相关的知识,希望对你有一定的参考价值。

<?php
//https://github.com/evernote/evernote-cloud-sdk-php
/**
way 1: oauth2
*/
//set this to false to use in production
$sandbox = true;

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

$key      = 'hoangweb';
$secret   = '93b39ab980c30dae';
$callback = 'http://localhost/test/php/evernote.php';
$oauth_data  = $oauth_handler->authorize($key, $secret, $callback);	//login with dev account

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

/**
way 2: generate dev developer token
*/
//### simple client
$token='S=s1:U=951df:E=16f9c6d9846:C=16844bc6968:P=1cd:A=en-devtoken:V=2:H=68a9a7203849b2e86aa52e0096760d56';
$client = new \Evernote\Client($token, $sandbox);

# get advanced client from simple client
$advancedClient = $client->getAdvancedClient();

//### advance client
$sandbox = true;
$advancedClient = new \Evernote\AdvancedClient($token, $sandbox);

#--------------------------------------------------------------
/**
	working with note
*/
//get note
$client->getNote('the-note-guid');

/*
create a note: https://github.com/evernote/evernote-cloud-sdk-php/blob/master/sample/client/create_note.php
*/
$note         = new \Evernote\Model\Note();
$note->title  = 'Test note';
$note->content = new \Evernote\Model\PlainTextNoteContent('Some plain text content.');
$note->tagNames = array('tag1', 'tag2');
$notebook = null;
$t=$client->uploadNote($note, $notebook);
print_r($t);

# for html
$html1 = new \Evernote\Model\HtmlNoteContent('<b>dfsf</b>');
$html1->setBaseUrl('http://www.google.com');
$note->content = $html1;

//delete a note
$note = new \Evernote\Model\Note();
$note->guid = 'GUID';
$client->deleteNote($note);

/*
share a note: ex of share url: https://sandbox.evernote.com/shard/s1/sh/8d47cc8f-18d8-4464-a27e-14cfc1578079/c3fda8ae69e3e84d5f9dc09d1e8edb08
-> note ID= 8d47cc8f-18d8-4464-a27e-14cfc1578079
*/
$uploaded_note = $client->uploadNote($note);
echo "\nPublic link : " .$client->shareNote($uploaded_note);

/**
add resource to a note: https://github.com/evernote/evernote-cloud-sdk-php/blob/master/sample/client/add_resource.php
*/
$resource = new \Evernote\Model\Resource('D:\tmp/test123.jpg', 'image/png', 100, 100);
// Get a preformatted enml media tag (something like '<en-media type="%mime%" hash="%hash%" />')
$enml_media_tag = $resource->getEnmlMediaTag();
// Create the note
$note = new \Evernote\Model\Note();
$note->addResource($resource);
$note->title  = 'Test note '.rand(0,1000);
$note->content = new \Evernote\Model\EnmlNoteContent(
    <<<ENML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note>$enml_media_tag</en-note>
ENML
);
$uploaded_note = $client->uploadNote($note);

//note: how to mix resource & text/html
$note->content = new \Evernote\Model\EnmlNoteContent(
    <<<ENML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note>$enml_media_tag</en-note>
<strong>any html</strong><br/>
<a href="http://hoangweb.com" target="_blank">XX</a>

ENML
);

/*
print binary resource: but you can't get image link to embed on web
*/
$note = $client->getNote('8d47cc8f-18d8-4464-a27e-14cfc1578079');
$resources = $note->getResources();

header('content-type: image/png');
$img = $resources[0];
print_r($img->data->body);

#other
$img->mime;	//image/png
//EDAM\Types\ResourceAttributes Object ( [sourceURL] => [timestamp] => [latitude] => [longitude] => [altitude] => [cameraMake] => [cameraModel] => [clientWillIndex] => [recoType] => [fileName] => test123.jpg [attachment] => [applicationData] => )
$fileName = $img->attributes['fileName'];
$img->guid;	//sourceURL: https://sandbox.evernote.com/shard/s1/res/<guid>/$fileName
$img->noteGuid;	//main note contain this resource

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

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

以上是关于php [evernote php] evernote api https://github.com/evernote/evernote-cloud-sdk-php #note的主要内容,如果未能解决你的问题,请参考以下文章

linux下安装evernote国际版

EVERNOTE 的 JAVASCRIPT SDK 问题

Apple标签,Apple脚本和Evernote

如何保存与evernote类似的所有样式和图像的网页?

Evernote Android API 坏了?共享文档的意图不再有效

如何像evernote -iphone那样实现编辑