3

我以前使用过 OAuth(使用 Twitter 和 PHP),这很简单。我正在尝试让 OAuth 与 EverNote API 示例https://github.com/evernote/evernote-sdk-csharp一起使用(因为正如他们所说,“真正的应用程序使用 OAuth 通过 Evernote 进行身份验证”)。我看了这些:

简单的 C# Evernote API OAuth 示例或指南?

https://github.com/sethhitch/csharp-oauth-sample

http://blog.stevienova.com/2008/04/19/oauth-getting-started-with-oauth-in-c-net/

但是,我仍然不知道该怎么做......这是我的代码:

    // Real applications authenticate with Evernote using OAuth, but for the
    // purpose of exploring the API, you can get a developer token that allows
    // you to access your own Evernote account. To get a developer token, visit 
    // https://sandbox.evernote.com/api/DeveloperToken.action
    String authToken = "myAuthCode";

    if (authToken == "your developer token") {
      Console.WriteLine("Please fill in your developer token");
      Console.WriteLine("To get a developer token, visit https://sandbox.evernote.com/api/DeveloperToken.action");
      return;
    }

如何将 OAuth 添加到此以获取我的authToken?

谢谢你。

4

4 回答 4

7

检查这个示例项目:http ://discussion.evernote.com/topic/30584-here-is-a-net-oauth-assembly/ 。我认为这将帮助您了解 oauth 的工作原理。

于 2013-02-28T18:17:39.367 回答
2

对于任何试图让它在 MVC 中工作的人,我今天早上正在玩 Evernote、OpenAuth 和 C#,并设法让它全部工作。我已经整理了一篇博客文章/库,解释了经验并概述了如何使用 MVC 在这里 - http://www.shaunmccarthy.com/evernote-oauth-csharp/ - 它使用 AsyncOAuth 库:https://github .com/neuecc/AsyncOAuth

我围绕 AsyncOAuth 编写了一个包装器,您可能会在这里发现它很有用:https ://github.com/shaunmccarthy/AsyncOAuth.Evernote.Simple

需要注意的一件棘手的事情 - Evernote 端点(/oauth 和 /OAuth.action)区分大小写

// Download the library from https://github.com/shaunmccarthy/AsyncOAuth.Evernote.Simple

// Configure the Authorizer with the URL of the Evernote service,
// your key, and your secret. 
var EvernoteAuthorizer = new EvernoteAuthorizer(
    "https://sandbox.evernote.com", 
    "slyrp-1234", // Not my real id / secret :)
    "7acafe123456badb123");

// First of all, get a request token from Evernote - this causes a 
// webrequest from your server to Evernote.
// The callBackUrl is the URL you want the user to return to once
// they validate the app
var requestToken = EvernoteAuthorizer.GetRequestToken(callBackUrl);

// Persist this token, as we are going to redirect the user to 
// Evernote to Authorize this app
Session["RequestToken"] = requestToken;

// Generate the Evernote URL that we will redirect the user to in
// order to 
var callForwardUrl = EvernoteAuthorizer.BuildAuthorizeUrl(requestToken);

// Redirect the user (e.g. MVC)
return Redirect(callForwardUrl);

// ... Once the user authroizes the app, they get redirected to callBackUrl

// where we parse the request parameter oauth_validator and finally get
// our credentials
// null = they didn't authorize us
var credentials = EvernoteAuthorizer.ParseAccessToken(
    Request.QueryString["oauth_verifier"], 
    Session["RequestToken"] as RequestToken);

// Example of how to use the credential with Evernote SDK
var noteStoreUrl = EvernoteCredentials.NotebookUrl;
var noteStoreTransport = new THttpClient(new Uri(noteStoreUrl));
var noteStoreProtocol = new TBinaryProtocol(noteStoreTransport);
var noteStore = new NoteStore.Client(noteStoreProtocol);
List<Notebook> notebooks = client.listNotebooks(EvernoteCredentials.AuthToken);
于 2013-09-28T17:38:27.283 回答
1

您还可以尝试在此处找到的 OAuth 库:https ://code.google.com/p/devdefined-tools/wiki/OAuth并按照此处提到的步骤进行操作。

于 2013-03-01T03:33:04.237 回答
0

要添加的简单代码是:

EvernoteOAuth oauth = new EvernoteOAuth(EvernoteOAuth.HostService.Sandbox, myConsumerKey, myConsumerSecret);
        string errResponse = oauth.Authorize();
        if (errResponse.Length == 0)
        {
            Console.WriteLine(string.Format("Token: {0}\r\n\r\nExpires: {1}\r\n\r\nNoteStoreUrl: {2}\r\n\r\nUserId: {3}\r\n\r\nWebApiUrlPrefix: {4}", oauth.Token, oauth.Expires, oauth.NoteStoreUrl, oauth.UserId, oauth.WebApiUrlPrefix));
        }
        else
        {
            Console.WriteLine("A problem has occurred in attempting to authorize the use of your Evernote account: " + errResponse);
        }

您将需要使用此程序集:

using EvernoteOAuthNet;

可在此处获得:

http://www32.zippyshare.com/v/98249023/file.html

于 2013-02-28T19:12:58.183 回答