As many people before me, I'm failing miserably to successfully save an access token between launches of my application. This application is actually only going to be used with one specific dropbox account, though I'm trying to make it easy to set up and a bit more dynamic.
Of course, if the settings are empty (initial run), the user can correctly log in and authorize the app, and coming back to the app it works as intended. On subsequent runs, however, when it grabs the token and secret from the settings collection it fails miserably with
Received Response [Unauthorized] : Expected to see [OK]. The HTTP response was [{"error": "Invalid signature."}].
I'm obviously doing something wrong, what is it? Thanks!
Code below!
using System;
using DropNet;
namespace DS_Uploader_DropBox {
class Program {
private const string AppKey = "my super secret app key";
private const string AppSecret = "my super secret app secret";
static void Main(string[] args) {
DropNetClient client;
DropNet.Models.UserLogin token;
string userToken = Settings.Default.userToken;
string userSecret = Settings.Default.userSecret;
bool needAccessToken = (String.IsNullOrEmpty(userToken) || string.IsNullOrEmpty(userSecret));
//needAccessToken = true;
if (needAccessToken) {
client = new DropNet.DropNetClient(AppKey, AppSecret);
client.UseSandbox = true;
client.GetToken();
// Auth with dropbox
var url = client.BuildAuthorizeUrl();
// Prompt for user to auth
Console.WriteLine("go auth here " + url);
Console.ReadLine();
// If the user authed, let's get that token
try {
token = client.GetAccessToken();
}
catch (Exception e) {
Console.WriteLine("Exception! " + e.Message);
return;
}
// save for later
userToken = token.Token;
userSecret = token.Secret;
Settings.Default.userToken = userToken;
Settings.Default.userSecret = userSecret;
Settings.Default.Save();
} else {
client = new DropNet.DropNetClient(AppKey, AppSecret, userToken, userSecret);
client.UseSandbox = true;
client.GetToken();
// get that token
try {
token = client.GetAccessToken();
} catch (Exception e) {
Console.WriteLine("Exception! " + e.Message);
return;
}
}
var acctInfo = client.AccountInfo();
Console.WriteLine(acctInfo.display_name);
Console.ReadLine();
}
}
}
Code that worked to follow:
using System;
using DropNet;
namespace DS_Uploader_DropBox {
class Program {
private const string AppKey = "my super secret app key";
private const string AppSecret = "my super secret app secret";
static void Main(string[] args) {
DropNetClient client;
DropNet.Models.UserLogin token;
string userToken = Settings.Default.userToken;
string userSecret = Settings.Default.userSecret;
bool needAccessToken = (String.IsNullOrEmpty(userToken) || string.IsNullOrEmpty(userSecret));
//needAccessToken = true;
if (needAccessToken) {
client = new DropNet.DropNetClient(AppKey, AppSecret);
client.UseSandbox = true;
client.GetToken();
// Auth with dropbox
var url = client.BuildAuthorizeUrl();
// Prompt for user to auth
Console.WriteLine("go auth here " + url);
Console.ReadLine();
// If the user authed, let's get that token
try {
token = client.GetAccessToken();
}
catch (Exception e) {
Console.WriteLine("Exception! " + e.Message);
return;
}
// save for later
userToken = token.Token;
userSecret = token.Secret;
Settings.Default.userToken = userToken;
Settings.Default.userSecret = userSecret;
Settings.Default.Save();
} else {
client = new DropNet.DropNetClient(AppKey, AppSecret, userToken, userSecret);
client.UseSandbox = true;
}
var acctInfo = client.AccountInfo();
Console.WriteLine(acctInfo.display_name);
Console.ReadLine();
}
}
}