<C#>Dropbox APIs

來源:互聯網
上載者:User

標籤:style   blog   class   code   java   tar   

第一步,啟用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。

第三步,編程

 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 DropNetDemo12 {13     public partial class Form1 : Form14     {15         #region Var16         private DropNetClient _dropNetClient;17         #endregion18 19         #region Private Property20         private DropNetClient m_DropNetClient21         {22             get23             {24                 return _dropNetClient ?? (_dropNetClient = new DropNetClient(tbxAppKey.Text, tbxAppSecret.Text));25             }26             set27             {28                 _dropNetClient = value;29             }30         }31         #endregion32 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.Fill57                 };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 }

最後,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

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.