The PHP OAuth Extension is not installed"); } // Verify that you have configured your API key if (OAUTH_CONSUMER_KEY == 'en-edamtest') { $configFile = dirname(__FILE__) . '/config.php'; die("Before using this sample code you must edit the file $configFile " . "and replace OAUTH_CONSUMER_KEY and OAUTH_CONSUMER_SECRET with the values that you received from Evernote. " . "If you do not have an API key, you can request one from " . "http://www.evernote.com/about/developer/api/"); } /* * The first step of OAuth authentication: the client (this application) * obtains temporary credentials from the server (Evernote). * * After successfully completing this step, the client has obtained the * temporary credentials identifier, an opaque string that is only meaningful * to the server, and the temporary credentials secret, which is used in * signing the token credentials request in step 3. * * This step is defined in RFC 5849 section 2.1: * http://tools.ietf.org/html/rfc5849#section-2.1 * * @return boolean TRUE on success, FALSE on failure */ function getTemporaryCredentials() { global $lastError, $currentStatus; try { $oauth = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET); $requestTokenInfo = $oauth->getRequestToken(REQUEST_TOKEN_URL, getCallbackUrl()); if ($requestTokenInfo) { $temporaryCredArray['requestToken'] = $requestTokenInfo['oauth_token']; $temporaryCredArray['requestTokenSecret'] = $requestTokenInfo['oauth_token_secret']; $temporaryCredArray['status'] = 'success'; return $temporaryCredArray; } else { $lastError = 'Failed to obtain temporary credentials: ' . $oauth->getLastResponse(); } } catch (OAuthException $e) { $lastError = 'Error obtaining temporary credentials: ' . $e->getMessage(); } return false; } /* * The completion of the second step in OAuth authentication: the resource owner * authorizes access to their account and the server (Evernote) redirects them * back to the client (this application). * * After successfully completing this step, the client has obtained the * verification code that is passed to the server in step 3. * * This step is defined in RFC 5849 section 2.2: * http://tools.ietf.org/html/rfc5849#section-2.2 * * @return boolean TRUE if the user authorized access, FALSE if they declined access. */ function handleCallback() { global $lastError, $currentStatus; if (isset($_GET['oauth_verifier'])) { $oauthVerifier['oauth_verifier'] = $_GET['oauth_verifier']; $oauthVerifier['status'] = 'success'; } else { // If the User clicks "decline" instead of "authorize", no verification code is sent $oauthVerifier['refurl'] = $_GET['refer_url']; $oauthVerifier['status'] = 'declined'; } return $oauthVerifier; } /* * The third and final step in OAuth authentication: the client (this application) * exchanges the authorized temporary credentials for token credentials. * * After successfully completing this step, the client has obtained the * token credentials that are used to authenticate to the Evernote API. * * This step is defined in RFC 5849 section 2.3: * http://tools.ietf.org/html/rfc5849#section-2.3 * * @return boolean TRUE on success, FALSE on failure */ function getTokenCredentials($requestToken,$requestTokenSecrent,$oauth_verifier) { global $lastError, $currentStatus; try { $oauth = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET); $oauth->setToken($requestToken, $requestTokenSecrent); $accessTokenInfo = $oauth->getAccessToken(ACCESS_TOKEN_URL, null, $oauth_verifier); if ($accessTokenInfo) { $accessTokenArray['accessToken'] = $accessTokenInfo['oauth_token']; $accessTokenArray['accessTokenSecret'] = $accessTokenInfo['oauth_token_secret']; $accessTokenArray['shardId'] = $accessTokenInfo['edam_shard']; $accessTokenArray['edamUserId'] = $accessTokenInfo['edam_userId']; $accessTokenArray['status'] = 'success'; $currentStatus = 'Exchanged the authorized temporary credentials for token credentials'; return $accessTokenArray; } else { $lastError = 'Failed to obtain token credentials: ' . $oauth->getLastResponse(); } } catch (OAuthException $e) { $lastError = 'Error obtaining token credentials: ' . $e->getMessage(); } return FALSE; } /* * List all notebook names for specific user * * @RETURN - array of notebook names */ function listNotebookz($userAccessToken,$shardid) { global $lastError, $currentStatus; $noteStoreTrans = new THttpClient(NOTESTORE_HOST, NOTESTORE_PORT, '/edam/note/' . $shardid, NOTESTORE_PROTOCOL); error_log("________".NOTESTORE_HOST); $noteStoreProt = new TBinaryProtocol($noteStoreTrans); $noteStore = new NoteStoreClient($noteStoreProt, $noteStoreProt); $authToken = $userAccessToken; $notebooks = $noteStore->listNotebooks($authToken); $result = array(); if (!empty($notebooks)) { foreach ($notebooks as $notebook) { $result[] = $notebook->name; } } $notebooksArray['notebooks'] = $result; $notebooksArray['status'] = 'success'; return $notebooksArray; } /* * Reset the current session. */ function resetSession() { if (isset($_SESSION['requestToken'])) { unset($_SESSION['requestToken']); } if (isset($_SESSION['requestTokenSecret'])) { unset($_SESSION['requestTokenSecret']); } if (isset($_SESSION['oauthVerifier'])) { unset($_SESSION['oauthVerifier']); } if (isset($_SESSION['accessToken'])) { unset($_SESSION['accessToken']); } if (isset($_SESSION['accessTokenSecret'])) { unset($_SESSION['accessTokenSecret']); } if (isset($_SESSION['shardId'])) { unset($_SESSION['shardId']); } if (isset($_SESSION['notebooks'])) { unset($_SESSION['notebooks']); } } /* * Get the URL of this application. This URL is passed to the server (Evernote) * while obtaining unauthorized temporary credentials (step 1). The resource owner * is redirected to this URL after authorizing the temporary credentials (step 2). */ function getCallbackUrl() { $thisUrl = (empty($_SERVER['HTTPS'])) ? "http://" : "https://"; $thisUrl .= $_SERVER['SERVER_NAME']; $thisUrl .= ($_SERVER['SERVER_PORT'] == 80 || $_SERVER['SERVER_PORT'] == 443) ? "" : (":".$_SERVER['SERVER_PORT']); $thisUrl .= $_SERVER['SCRIPT_NAME']; $thisUrl .= '?action=callback&refer_url='.$_SERVER['HTTP_REFERER']; //$thisURL = $_SERVER['HTTP_REFERER']; //$thisUrl .= '?action=callback'; //echo $thisURL; //exit; return $thisUrl; } /* * Get the Evernote server URL used to authorize unauthorized temporary credentials. */ function getAuthorizationUrl($currentRequestToken) { $url = AUTHORIZATION_URL; $url .= '?oauth_token='; $url .= urlencode($currentRequestToken); return $url; } function addArticleClip($userAuthToken,$userAuthShard,$clipTitle="An Inc.com Article",$clipContent="No Content, Sorry!",$clipurl="http://www.inc.com"){ $noteStoreTrans = new THttpClient(NOTESTORE_HOST, NOTESTORE_PORT, '/edam/note/' . $userAuthShard, NOTESTORE_PROTOCOL); $noteStoreProt = new TBinaryProtocol($noteStoreTrans); $noteStore = new NoteStoreClient($noteStoreProt, $noteStoreProt); $authToken = $userAuthToken; $noteattributes = new edam_type_NoteAttributes(); $noteattributes->sourceURL = $clipurl; $newNote = new edam_type_Note(); $newNote->title = $clipTitle; $newNote->attributes = $noteattributes; $enml = '
'.$clipContent.'
'; $newNote->content = $enml; $serverNote = $noteStore->createNote($authToken, $newNote); } ?>