public static void GetAccessToken <T>(Action <T> cb) { var data = new YNoteRequestData(); data.httpVerb = HTTPVerb.POST; data.url = YNoteUtil.GetURL(OAUTH1_ACCESS_TOKEN); string http = YNoteOAuthUtil.GetHttpVerbName(data.httpVerb); string callback = OAUTH_CALLBACK; string method = OAUTH_SHA1; string timeStamp = YNoteOAuthUtil.GenerateTimeStampSec(); string nonce = YNoteOAuthUtil.GenerateNonce(); string ver = OAUTH_VER; string oauth_token = YNoteUtil.oauth_token; string oauth_token_secret = YNoteUtil.oauth_token_secret; string oauth_verifier = YNoteUtil.oauth_verifier; data.content = new Dictionary <string, string>(); data.content.Add("oauth_consumer_key", YNoteUtil.consumerKey); // consumerKey data.content.Add("oauth_token", oauth_token); // 请求 request_token 时返回的 oauth_token data.content.Add("oauth_verifier", oauth_verifier); // 授权码 data.content.Add("oauth_signature_method", method); // 签名方法 data.content.Add("oauth_timestamp", timeStamp); // 时间戳 data.content.Add("oauth_nonce", nonce); // 随机串 data.content.Add("oauth_version", ver); // oauth 版本 string signature = YNoteOAuthUtil.GenerateOAuthSignature(http, data.url, data.content, YNoteUtil.consumerSecret, oauth_token_secret); data.content.Add("oauth_signature", signature); // 签名 YNoteRequestManager.Instance.ParseRequest(data, cb); }
private static void AppendOAuthContent(ref YNoteRequestData data) { string method = OAUTH_SHA1; string timeStamp = YNoteOAuthUtil.GenerateTimeStampSec(); string nonce = YNoteOAuthUtil.GenerateNonce(); string ver = OAUTH_VER; string oauth_token = YNoteUtil.access_token; data.content = new Dictionary <string, string>(); data.content.Add("oauth_consumer_key", YNoteUtil.consumerKey); // consumerKey data.content.Add("oauth_token", oauth_token); // oauth_token data.content.Add("oauth_signature_method", method); // 签名方法 data.content.Add("oauth_timestamp", timeStamp); // 时间戳 data.content.Add("oauth_nonce", nonce); // 随机串 data.content.Add("oauth_version", ver); // oauth 版本 }
public static void GetAllNotebook <T>(Action <T> cb) { var data = new YNoteRequestData(); data.httpVerb = HTTPVerb.POST; data.url = YNoteUtil.GetURL(API_ALL_NOTEBOOK); AppendOAuthContent(ref data); string http = YNoteOAuthUtil.GetHttpVerbName(data.httpVerb); string oauth_token_secret = YNoteUtil.access_token_secret; string signature = YNoteOAuthUtil.GenerateOAuthSignature(http, data.url, data.content, YNoteUtil.consumerSecret, oauth_token_secret); data.content.Add("oauth_signature", signature); // 签名 YNoteRequestManager.Instance.ParseRequest(data, cb); }
public static void GetUserInfo <T>(Action <T> cb) { var data = new YNoteRequestData(); data.httpVerb = HTTPVerb.GET; data.url = YNoteUtil.GetURL(API_USER_INFO); AppendOAuthContent(ref data); string http = YNoteOAuthUtil.GetHttpVerbName(data.httpVerb); string oauth_token_secret = YNoteUtil.access_token_secret; string signature = YNoteOAuthUtil.GenerateOAuthSignature(http, data.url, data.content, YNoteUtil.consumerSecret, oauth_token_secret); data.content.Add("oauth_signature", signature); // 签名 data.url = YNoteOAuthUtil.GenerateQueryString(data.url, data.content); YNoteRequestManager.Instance.ParseRequest(data, cb); }
public static void MoveNote <T>(string notePath, string targetNotebook, Action <T> cb) { var data = new YNoteRequestData(); data.httpVerb = HTTPVerb.POST; data.url = YNoteUtil.GetURL(API_MOVE_NOTE); AppendOAuthContent(ref data); data.content.Add("path", notePath); data.content.Add("notebook", targetNotebook); string http = YNoteOAuthUtil.GetHttpVerbName(data.httpVerb); string oauth_token_secret = YNoteUtil.access_token_secret; string signature = YNoteOAuthUtil.GenerateOAuthSignature(http, data.url, data.content, YNoteUtil.consumerSecret, oauth_token_secret); data.content.Add("oauth_signature", signature); // 签名 YNoteRequestManager.Instance.ParseRequest(data, cb); }
public static void CreateNote <T>(string source, string author, string title, string content, Action <T> cb) { var data = new YNoteRequestData(); data.httpVerb = HTTPVerb.POST; data.url = YNoteUtil.GetURL(API_NEW_NOTE); data.contentType = HTTPContentType.MULTIPART; AppendOAuthContent(ref data); string http = YNoteOAuthUtil.GetHttpVerbName(data.httpVerb); string oauth_token_secret = YNoteUtil.access_token_secret; string signature = YNoteOAuthUtil.GenerateOAuthSignature(http, data.url, data.content, YNoteUtil.consumerSecret, oauth_token_secret); data.content.Add("oauth_signature", signature); // 签名 data.content.Add("source", source); data.content.Add("author", author); data.content.Add("title", title); data.content.Add("content", content); YNoteRequestManager.Instance.ParseRequest(data, cb); }