首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过OAuth的Evernote AuthToken

通过OAuth的Evernote AuthToken
EN

Stack Overflow用户
提问于 2013-03-01 01:16:31
回答 4查看 1.8K关注 0票数 3

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

Simple C# Evernote API OAuth example or guide?

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

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

但是,我还是不知道该怎么做。这是我的代码:

代码语言:javascript
复制
    // 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

谢谢。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2013-03-01 03:12:58

要添加的简单代码是:

代码语言:javascript
复制
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);
        }

您将需要使用此程序集:

代码语言:javascript
复制
using EvernoteOAuthNet;

可在此处获得:

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

票数 0
EN

Stack Overflow用户

发布于 2013-03-01 02:17:39

检查这个样例项目:http://discussion.evernote.com/topic/30584-here-is-a-net-oauth-assembly/。我认为这将帮助你理解oauth是如何工作的。

票数 7
EN

Stack Overflow用户

发布于 2013-09-29 01:38:27

对于任何想要在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)区分大小写

代码语言:javascript
复制
// 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);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15141655

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档