无法通过Evernote Api授权

时间:2013-04-08 10:49:26

标签: c++ evernote

我想为Evernote创建一个小客户端。

我从网站上获得了消费者密钥和秘密,并编写了这段代码:

struct user_data {
    std::string login;
    std::string pass;
};

struct evernote_data {
    user_data user;
    std::string consumer_key;
    std::string consumer_secret;
};

struct service_data
{
    std::string host;
    std::string path;
    int port;
};

void connect(const evernote_data& account, const service_data&  service)
{
    try
    {
        boost::shared_ptr<TSSLSocketFactory> sslSocketFactory(new TSSLSocketFactory());
        boost::shared_ptr<TSSLSocket> sslSocket=sslSocketFactory->createSocket(service.host, service.port);
        boost::shared_ptr<TBufferedTransport> bufferedTransport(new TBufferedTransport(sslSocket));
        boost::shared_ptr<TTransport> http_client(new THttpClient(bufferedTransport, service.host, service.path));
        http_client->open();
        boost::shared_ptr<TBinaryProtocol> user_store_protocol(new TBinaryProtocol(http_client));
        evernote::edam::UserStoreClient user_store(user_store_protocol, user_store_protocol);

        evernote::edam::AuthenticationResult auth_result;
        user_store.authenticate(auth_result, account.user.login, account.user.pass, account.consumer_key, account.consumer_secret);
        cout << "Some info: " ;
        cout << auth_result.user.username << endl << auth_result.user.name << endl << auth_result.user.email << endl;
    }
    catch(evernote::edam::EDAMUserException& error)
    {
        cout << "catch EDAMUserException" << endl;
        cout << "ErrorCode: " << error.errorCode << endl;
        cout << "What: " << error.what() << endl;
        cout << "Parameter: " << error.parameter << endl;
    }
    catch(::apache::thrift::TException& error)
    {
        cout << "catch thrift::TException " << endl;
        cout << "What: " << error.what() << endl;
    }
    catch(...)
    {
        cout << "boom !!!" << endl;
    }
}

int main()
{
    const user_data user = { "**Login**", "**password**"};
    const evernote_data account = { user, "***Key***", "**Secret**" };
    const service_data service = {"sandbox.evernote.com", "/edam/user", 443 };
    connect(account, service);

    std::cout << "Exit" << std::endl;
    cin.get();
    return 0;
}

节目输出:

Catch EDAMUserException 
ErrorCode: 8 
What: Default TException.
Parameter: consumerKey

并始终捕获有关错误的消费者密钥的错误。我究竟做错了什么?

1 个答案:

答案 0 :(得分:0)

自去年11月以来,第三方开发人员无法使用UserStore#authenticate。 http://dev.evernote.com/documentation/reference/UserStore.html#Fn_UserStore_authenticate

请改用OAuth。 http://dev.evernote.com/start/core/authentication.php