How to use the Evernote API SDK with PHP-OAuth on Google Code

Posted by | November 28, 2011 | Digital Marketing | 10 Comments

For developers integrating the Evernote API into your PHP web applications, we have found there are certain issues you are likely run in to. Firstly when you download, configure and run The Evernote API SDK for PHP, most web servers will cause the script to complain stating that the PECL OAuth Extension must be installed. Installing the PECL OAuth extension is relatively straight-forward if you have SSH command line access to your server.

However, for most people installing the extension is simply not an option. There are major conflicts with the PECL OAuth PHP extension and the OAuth libraries available for download from Google Code SVN. One example of this would be: Installing the PECL OAuth extension prevents the standard OAuth libraries from functioning altogether and this will be an issue for all websites hosted on the same server. Furthermore, you may not have access to the server command line needed to install the extension, or your web host may not allow the extension to be installed for various reasons.

The simple truth is that although the Evernote API PHP SDK states that the PECL PHP OAuth extension is required, the SDK can easily be adapted for use the with standard OAuth library that most developers are akin to working with.

The solution and the source code

You will need…

Instructions for setting it up…

  1. Create a public folder called ‘/evernote/’ on your server, it will run the ‘OAuth dance’ process from here.
  2. In the Evernote SDK files, browse to the folder: ‘/php/sample/oauth/’ and upload the contents of it to your new ‘evernote’ folder on the server.
  3. Upload the OAuth-PHP ‘/library/…’ files to a new folder in ‘/evernote/’ called: ‘/oauth/’. So that the file ‘/evernote/oauth/OAuthRequester.php’ will exists publicly on the server.
  4. Add your API Key and other credentials to the ‘/evernote/config.php’ file and configure the sandbox/production URL’s if desired.
  5. Time to code. First, replace the ‘/evernote/index.php’ contents with the following code:

You will need to modify the ‘/evernote/oauth/OAuthRequester.php’ ‘requestAccessToken()’ function slightly to provide you with the Evernote API access credentials needed to make any future requests to the Evernote API. This information can be saved to a database, however for simplicity we have saved them in session variables. In Evernote, the information you need for future requests is known as a ‘Credentials Identifier’. To set this up, simply add the following 3 lines of code immediately after the line with a call to: ‘$store->addServerToken();’:

Lastly, you should replace the listNotebooks() function in ‘/evernote/functions.php’ with this:

That’s all there is to it. If you save and upload all of the modified files and navigate your browser to your ‘/evernote/’ folder, it will redirect you to the Evernote authorize page prompting you to login with your Evernote Account. Upon doing so, you will be immediately redirected back to your ‘/evernote/’ folder where you will see your array of Notebooks output in a recursive, human-readable format. You can now do as you please with the array of notebooks in the ‘/evernote/index.php’ file. You can also utilize the same code to develop additional or alternate Evernote API request functionality such as returning lists of notes, tags, creating tags and more.

Include the config.php and functions.php in other scripts which handle your form data, then implement your own functions to make use of the Evernote API.


    Find out more & get connected:
  • twitter

About admin


  • emilieeee

    Hi, i followed the steps but met with some errors. any help for that?

    OAuthException: CURL error: Proxy CONNECT abortedobject(OAuthException2)#3 (7) { [“message”:protected]=> string(33) “CURL error: Proxy CONNECT aborted” [“string”:”Exception”:private]=> string(0) “” [“code”:protected]=> int(0) [“file”:protected]=> string(49) “C:xampphtdocsevernoteoauthOAuthRequester.php” [“line”:protected]=> int(426) [“trace”:”Exception”:private]=> array(2) { [0]=> array(6) { [“file”]=> string(49) “C:xampphtdocsevernoteoauthOAuthRequester.php” [“line”]=> int(160) [“function”]=> string(8) “curl_raw” [“class”]=> string(14) “OAuthRequester” [“type”]=> string(2) “->” [“args”]=> array(1) { [0]=> array(0) { } } } [1]=> array(6) { [“file”]=> string(34) “C:xampphtdocsevernoteindex.php” [“line”]=> int(26) [“function”]=> string(19) “requestRequestToken” [“class”]=> string(14) “OAuthRequester” [“type”]=> string(2) “::” [“args”]=> array(3) { [0]=> string(6) “emilie” [1]=> int(0) [2]=> array(1) { [“oauth_callback”]=> string(18) “localhost/evernote” } } } } [“previous”:”Exception”:private]=> NULL }

  • emilieeee

    Hi, i’ve resolved the issues with the proxy. However, i’m getting the OAuth exception of token not return. i found out that the response return includes header for the proxy, which is like to cause the error, and way to resolve?

    • gavinpotts

      @emilieeee Hi, you can use: curl_setopt($ch, CURLOPT_HEADER, 0);to hide the cURL header output.Are you able to share some details such as the PHP version and cURL version? The code from this article has been tested on a production Linux server, so it’s not surprising to hear about problems using Windows-based servers. Make sure you are using the Evernote API sandbox, as this will be less restrictive to the development URL you are likely to be using at present.

  • thepeg

    anybody knows where to find an updated version of this article?

  • m.

    Hello, thanks for your little walkthrough … very helpful. Unfortunately your code escaping seems to be a little wonky, some code is put into comments and is only visible in the source.

    • yodelay

      Thanks for your feedback M we’ll take a look ;o)


  • Lokesh Kumar


    I have read this blog and found a solution for a problem I was struggling with for a few days. But there is one problem, if you see, the code which you have posted is not complete therefore I can not use it. It would be really nice of you if you could send me the code at .


  • Lokesh Kumar

    Hi all,

    Was anyone able to solve this problem of “The access token Request server did not return the oauth_token or the oauth_token_secret”.

    Please reply, I have spent a lot of time on this problem but still its not working. I also tried setting the curl header value to 0 but no luck yet.


  • nicolas

    code “” not visible :(

    please fix, and thanks !

  • nicolas

    the source code: