Dropbox APIs

第一步,激活Drive API

首先,申请Dropbox的帐号;其次,在Dropbox for Developers上获得开发所需的App Key和App Sercet。

1、登录Dropbox for Developers网站;2、点击App Console选项,选择Create app;3、点击Send email for verification;4、通过电子邮件验证;5、在Create a new Dropbox Platform app上,选择Dropbox API app;6、填写信息并Create app,就将获得App key和App secret。

第二步,安装Dropbox Client Library

安装一个NuGet包(Dropnet)。如VS2012选择Tools项,再选NuGet Package Manager,接着Package Manager Console。在PM>中填写Install-Package dropnet -Pre。

第三步,编程

<C#>Dropbox APIs
 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Windows.Forms;
 9 using DropNet;
10 
11 namespace DropNetDemo
12 {
13     public partial class Form1 : Form
14     {
15         #region Var
16         private DropNetClient _dropNetClient;
17         #endregion
18 
19         #region Private Property
20         private DropNetClient m_DropNetClient
21         {
22             get
23             {
24                 return _dropNetClient ?? (_dropNetClient = new DropNetClient(tbxAppKey.Text, tbxAppSecret.Text));
25             }
26             set
27             {
28                 _dropNetClient = value;
29             }
30         }
31         #endregion
32 
33         public Form1()
34         {
35             InitializeComponent();
36         }
37 
38         private void btnLogin_Click(object sender, EventArgs e)
39         {
40             var callbackUrl = "https://www.dropbox.com/1/oauth/authorize";
41             var cancelCallbackUrl = "https://www.dropbox.com/home";
42             var size = new Size(1024, 600);
43 
44             if (DoOAuth(callbackUrl, cancelCallbackUrl, size) == DialogResult.OK)
45             {
46                 var accessToken = m_DropNetClient.GetAccessToken();
47             }
48         }
49 
50         private DialogResult DoOAuth(string callbackUrl, string cancelCallbackUrl, System.Drawing.Size size)
51         {
52             using (var dialog = new Form())
53             {
54                 var browesr = new WebBrowser()
55                 {
56                     Dock = DockStyle.Fill
57                 };
58 
59                 m_DropNetClient.GetToken();
60                 var authUrl = m_DropNetClient.BuildAuthorizeUrl();
61                 browesr.Navigated += (s, ex) =>
62                 {
63                     var url = ex.Url.ToString();
64                     if (url.Equals(callbackUrl))
65                     {
66                         dialog.DialogResult = DialogResult.OK;
67                     }
68                     else if (url.Equals(cancelCallbackUrl))
69                     {
70                         dialog.DialogResult = DialogResult.Cancel;
71                     }
72                 };
73                 browesr.Navigate(authUrl);
74 
75                 dialog.Size = size;
76                 dialog.Controls.Add(browesr);
77 
78                 return dialog.ShowDialog();
79             }
80         }
81 
82         private void tbxAppKey_TextChanged(object sender, EventArgs e)
83         {
84             m_DropNetClient = null;
85         }
86 
87         private void tbxAppSecret_TextChanged(object sender, EventArgs e)
88         {
89             m_DropNetClient = null;
90         }
91     }
92 }
<C#>Dropbox APIs

最后,F5运行
源自:http://www.dotblogs.com.tw/larrynung/archive/2012/07/24/73580.aspx

http://www.dotblogs.com.tw/larry/nung/archive/2012/08/08/73912.aspx

 

<C#>Dropbox APIs,布布扣,bubuko.com

<C#>Dropbox APIs

上一篇:DataWindow快速从Grid格式转为Freefrom


下一篇:Google Drive APIs