Use Dropbox API v1 to get account info for public folder support

This commit is contained in:
Jaex 2016-07-03 03:06:13 +03:00
parent b82c386d59
commit ebea75d076
3 changed files with 28 additions and 4 deletions

View file

@ -97,6 +97,7 @@ public sealed class Dropbox : FileUploader, IOAuth2Basic
private const string URLCreateFolder = URLAPI + "/files/create_folder";
private const string URLDelete = URLAPI + "/files/delete";
private const string URLMove = URLAPI + "/files/move";
private const string URLAccountInfo = "https://api.dropbox.com/1/account/info"; // API v1
private const string URLPublicDirect = "https://dl.dropboxusercontent.com/u";
private const string URLShareDirect = "https://dl.dropboxusercontent.com/s";
@ -203,6 +204,29 @@ public DropboxAccount GetCurrentAccount()
return account;
}
// API v1
public DropboxAccountInfo GetAccountInfo()
{
DropboxAccountInfo account = null;
if (OAuth2Info.CheckOAuth(AuthInfo))
{
string response = SendRequest(HttpMethod.GET, URLAccountInfo, headers: GetAuthHeaders());
if (!string.IsNullOrEmpty(response))
{
account = JsonConvert.DeserializeObject<DropboxAccountInfo>(response);
if (account != null)
{
AccountInfo = account;
}
}
}
return account;
}
public bool DownloadFile(string path, Stream downloadStream)
{
if (!string.IsNullOrEmpty(path) && OAuth2Info.CheckOAuth(AuthInfo))

View file

@ -468,12 +468,12 @@ public void DropboxAuthComplete(string code)
if (result)
{
Config.DropboxAccount = dropbox.GetCurrentAccount();
Config.DropboxAccountInfo = dropbox.GetAccountInfo();
UpdateDropboxStatus();
oauth2Dropbox.Status = OAuthLoginStatus.LoginSuccessful;
if (Config.DropboxAccount != null)
if (Config.DropboxAccountInfo != null)
{
MessageBox.Show(Resources.UploadersConfigForm_Login_successful, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
@ -492,7 +492,7 @@ public void DropboxAuthComplete(string code)
}
}
Config.DropboxAccount = null;
Config.DropboxAccountInfo = null;
UpdateDropboxStatus();
}
catch (Exception ex)

View file

@ -130,7 +130,7 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
// Dropbox
public OAuth2Info DropboxOAuth2Info = null;
public DropboxAccount DropboxAccount = null;
//public DropboxAccount DropboxAccount = null;
public string DropboxUploadPath = "Public/ShareX/%y/%mo";
public bool DropboxAutoCreateShareableLink = false;
public DropboxURLType DropboxURLType = DropboxURLType.Default;