📜 ⬆️ ⬇️

QEverCloud: Evernote SDK for Qt

Since you are reading this post, you probably know what Evernote is. And of course you know what Qt is :)
And maybe you, like me, wanted to unite them.



If you tried to implement such a union - write a program in C ++ / Qt that would appeal to the Evernote Cloud API - then you already know that this is, to put it mildly, a trivial matter. For C ++, the creators of Evernote offer only files generated by the Thrift compiler . From them to something somehow working - as before the moon, and, unfortunately, not at all in a straight line.
')
I walked this path and, based on the results of this memorable journey, I decided that sending people to this path was not very humane. So in the end I wrote my library and uploaded it to GitHub .

How is QEverCloud better than Evernote SDK?



As an example of use, here is a simple little program that creates a test note in the default notepad:

 #include <QCoreApplication>
 #include <QTextStream>
 #include <exception>
 #include <QEverCloud.h>

 using namespace qevercloud;


 int main (int argc, char * argv [])
 {
     QCoreApplication a (argc, argv);
     QTextStream cout (stdout);
     try {
         NoteStore * ns = new NoteStore (& a);

         // insert your developer token here
         // https://www.evernote.com/api/DeveloperToken.action
         ns-> setAuthenticationToken ("S = s41: U = 427a0c: E = 14761d37b39: C = 1400a224f39: P = 1cd: A = en-devtoken: V = 2: H = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");

         // Find your NoteStore URL there
         ns-> setNoteStoreUrl ("https://www.evernote.com/shard/xxx/notestore");

         Note note;
         note.title = "Test Note";
         note.content = QString ("<? xml version = \" 1.0 \ "encoding = \" UTF-8 \ "?> \ n")
                 + "<! DOCTYPE en-note SYSTEM \" http: //xml.evernote.com/pub/enml2.dtd \ "> \ n"
                 + "<en-note>"
                 + "<b> Lives well in the world of Winnie the Pooh! </ b> <br /> <br /> <p> Hmm, it looks like <a href = \" https: //github.com/mgsxx/QEverCloud \ "> QEverCloud </a> does work ... </ p>"
                 + "</ en-note>";
         ns-> createNote (note);
     } catch (const std :: exception & e) {
         cout << "exception occured:" << e.what () << endl;
         return 1;
     } catch (...) {
         cout << "unknown exception occured!"  << endl;
         return 1;
     }
     return 0;
 }



Developer tokens are very convenient for your personal programs, but for more serious programs you need a token and NoteStore URLs to get an authorization through OAuth. Using QEverCloud makes it easy:

 #include <QEverCloudOAuth.h>

 ...

 // consumerKey and consumerSecret get here: https://dev.evernote.com/doc/, GET AN API KEY button
 EvernoteOAuthDialog d (consumerKey, consumerSecret, "sandbox.evernote.com");
 d.setWindowTitle ("Login to Evernote");
 if (d.exec ()! = QDialog :: Accepted) {
     QMessageBox :: critical (0, "Error", d.oauthError ());
 } else {
     QString authenticationToken = d.oauthResult (). AuthenticationToken;
     QString noteStoreUrl = d.oauthResult (). NoteStoreUrl;
 }

Source: https://habr.com/ru/post/216007/


All Articles