We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
karikalan
11 years agoNew member | Level 1
Windows 8 store app Dropbox get access token and upload issue
I am able to successfully login and get the request token using rest apin in Windows 8 store app. But I am getting '401 Unauthorized' error while retrieving the access token as well as trying to upl...
karikalan
11 years agoNew member | Level 1
We are using the following code and using OAuth1 and HMAC-SHA1 signing method.
var authentication = new Authentication(AppKey, AppSecret);
var token = await authentication.RequestToken("https://api.dropbox.com/1/oauth/request_token", WebAuthenticationBroker.GetCurrentApplicationCallbackUri().ToString());
if (token != null)
{
var url = "https://www.dropbox.com/1/oauth/authorize?oauth_token=" + token.Key + "&oauth_callback=" + WebAuthenticationBroker.GetCurrentApplicationCallbackUri();
System.Uri StartUri = new Uri(url);
WebAuthenticationResult WebAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(
WebAuthenticationOptions.None,
StartUri);
if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success)
{
authentication.GetAccessToken("https://api.dropbox.com/1/oauth/access_token?oauth_token=" + token.Key, token.Key, token.Secret);
Upload();
}
public async static void Upload()
{
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.FileTypeFilter.Add(".jpg");
picker.FileTypeFilter.Add(".png");
picker.FileTypeFilter.Add(".gif");
picker.FileTypeFilter.Add(".doc");
picker.FileTypeFilter.Add(".docx");
picker.FileTypeFilter.Add(".xls");
StorageFile attachmentFile = await picker.PickSingleFileAsync();
byte[] imgBytes = await GetPhotoBytesAsync(attachmentFile);
string apiKey ="yvynusucnu104zf" ;
string consumerSecret = "<redacted>";
string tokenKey = "vam1o365ldgp4wf7";
TimeSpan SinceEpoch = (DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime());
Random Rand = new Random();
Int32 Nonce = Rand.Next(1000000000);
var uri = new Uri(new Uri("https://api-content.dropbox.com/1/"),
String.Format("files_put/{0}/{1}",
"dropbox", @"Photos\car-acc2.jpg"));
var requestUri = SignRequest(uri, apiKey, consumerSecret, tokenKey, "PUT");
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(requestUri);
Request.Method = "PUT";
//Request.Headers["Authorization"] = Data;
using (Stream requestStream = await Request.GetRequestStreamAsync())
{
await requestStream.WriteAsync(imgBytes, 0, imgBytes.Length);
await requestStream.FlushAsync();
}
HttpWebResponse Response = (HttpWebResponse)await Request.GetResponseAsync();
StreamReader ResponseDataStream = new StreamReader(Response.GetResponseStream());
}
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!