Jul 16, 2012 at 5:52 PM
Edited Jul 16, 2012 at 5:53 PM
|
Does anyone know how to create a DropBoxToken? I can see that it gets returned when exchanging a Request Token for an Access Token. However, I can't get to through the API to set up a user connection. Or better yet, how to create a DropBoxCredential.
|
|
|
|
You need to use the DropBoxTokenIssuer.exe tool that is packaged with SharpBox. This will bring up a UI for you to enter the App Key and App Secret and then generate the Dropbox Token file. This file will be loaded by your application as in the
documentation:
using (FileStream fs = File.Open("DropboxToken.dbtkn", FileMode.Open, FileAccess.Read, FileShare.None))
{
accessToken = dropBoxStorage.DeserializeSecurityToken(fs);
}
|
|
Jul 17, 2012 at 2:00 PM
Edited Jul 17, 2012 at 2:44 PM
|
That would be a fine thing to do, except there is no documentation within the SharpBox v1.2 download on the use of the DropBoxTokenIssuer application. The only mention that I can even find for it is a couple of lines in the Quick Start Guide saying that
you must use it to generate a valid token file. And as I have previously posted the DropBoxTokenIssuer application keeps generating errors.
Additionally, if you will read further in the documentation (Step 5) you will see:
// open the connection
var StorageToken = dropBoxStorage.Open(dropBoxConfig, dropBoxCredentials);
The part I'm trying to get to is the creation of the dropBoxCredentials variable. That variable just magically appears in the documentation without ever being instantiated.
|
|
|
|
I see you're issue. This is an error in the documentation, the "dropBoxCredentials" is actually the "accessToken". I ran into this also, but noticed that the Type returned by DeserializeSecurityToken() is the same Type as dropBoxStorage.Open()'s
2nd argument, so I figured it was just an error in the example, and it was.
using (FileStream fs = File.Open("DropboxToken.dbtkn", FileMode.Open, FileAccess.Read, FileShare.None))
{
accessToken = dropBoxStorage.DeserializeSecurityToken(fs);
}
// open the connection
var storageToken = dropBoxStorage.Open(dropBoxConfig, accessToken);
|
|
|
|
In theory that sounds good. However, when I run the mini app I've created I get an exception trying to get the /Public folder.
AppLimit.CloudComputing.SharpBox.Exceptions.SharpBoxException was unhandled
Message=Couldn't retrieve child elements from the server
Source=AppLimit.CloudComputing.SharpBox
StackTrace:
at AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.Logic.DropBoxStorageProviderService.RequestResource(IStorageProviderSession session, String Name, ICloudDirectoryEntry parent)
at AppLimit.CloudComputing.SharpBox.StorageProvider.GenericStorageProvider.GetFileSystemObject(String path, ICloudDirectoryEntry parent)
at AppLimit.CloudComputing.SharpBox.CloudStorage.GetFileSystemObject(String name, ICloudDirectoryEntry parent)
at AppLimit.CloudComputing.SharpBox.CloudStorage.GetFolder(String path, ICloudDirectoryEntry parent)
at AppLimit.CloudComputing.SharpBox.CloudStorage.GetFolder(String path)
at TutApp01.Module1.Main() in C:\DEVELOP\ShaprBox Tutorial\TutApp01\TutApp01\Module1.vb:line 30
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Web.HttpException
ErrorCode=-2147467259
Message=HTTP Error
WebEventCode=0
InnerException:
My code is in VB and this is what I'm doing:
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Web
Imports AppLimit.CloudComputing.SharpBox
Imports AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox
Module Module1
Public dropBoxStorage As CloudStorage
Public AEDropBoxTkn As String = IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AdvisorExchange.dbtkn")
Sub Main()
' Creating cloudstorage object
dropBoxStorage = New CloudStorage
' Get the configuration for dropbox
Dim dropBoxConfig As DropBoxConfiguration = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox)
' Building credentials for the service
Dim accessToken As ICloudStorageAccessToken = Nothing
Using fs As IO.FileStream = IO.File.Open(AEDropBoxTkn, _
IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.None)
accessToken = dropBoxStorage.DeserializeSecurityToken(fs)
End Using
Dim storageToken = dropBoxStorage.Open(dropBoxConfig, accessToken)
' The exception is occuring at this statement
Dim publicFldr = dropBoxStorage.GetFolder("/Public")
For Each fof In publicFldr
If TypeOf fof Is ICloudDirectoryEntry Then
Console.WriteLine(String.Format("Dir: {0}", CType(fof, ICloudDirectoryEntry).Name))
ElseIf TypeOf fof Is ICloudFileSystemEntry Then
Console.WriteLine(String.Format("File: {0}", CType(fof, ICloudFileSystemEntry).Name))
End If
Next
dropBoxStorage.Close()
End Sub
End Module
|
|
|
|
Is SharpBox v1.2 broken for acessing DropBox now? I know that there are a lot of VB bigots out there so I took the time to rewrite my test app in C#. I'm still getting the same error. as above. Below is the test app code.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using AppLimit.CloudComputing.SharpBox;
using AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox;
namespace TutApp01CS
{
class Program
{
public static CloudStorage dropBoxStorage;
public static string AEDropBoxTkn = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AdvisorExchange.dbtkn");
static void Main(string[] args)
{
// Creating cloudstorage object
dropBoxStorage = new CloudStorage();
// Get the configuration for dropbox
DropBoxConfiguration dropBoxConfig = (DropBoxConfiguration)CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox);
// Building credentials for the service
ICloudStorageAccessToken accessToken = null;
using (FileStream fs = File.Open(AEDropBoxTkn, FileMode.Open, FileAccess.Read, FileShare.None))
{
accessToken = dropBoxStorage.DeserializeSecurityToken(fs);
}
var storageToken = dropBoxStorage.Open(dropBoxConfig, accessToken);
var publicFldr = dropBoxStorage.GetFolder("/Public");
foreach (var fof in publicFldr)
{
if (fof is ICloudDirectoryEntry)
{
Console.WriteLine(String.Format("Dir: {0}", ((ICloudDirectoryEntry)fof).Name));
}
else if (fof is ICloudFileSystemEntry)
{
Console.WriteLine(String.Format("File: {0}", ((ICloudDirectoryEntry)fof).Name));
}
}
dropBoxStorage.Close();
}
}
}
|
|
|
|
First, you need to fix the cast for file system entry. This is the correct cast:
else if (fof is ICloudFileSystemEntry)
{
Console.WriteLine(String.Format("File: {0}", ((ICloudFileSystemEntry)fof).Name));
}
After that, it worked fine for me:
C:\...\Visual Studio 2010\Projects\DropboxTest\DropboxTest\bin\Debug>DropboxTest.exe
File: How to use the Public folder.txt
|
|
|
|
Thanks, that is what I get for copy and pasting. If you can go back and read my initial thread, you'll see that I don't even get that far. I'm only getting as far as:
var publicFldr = dropBoxStorage.GetFolder("/Public");
before I get the above error message indicating that there is no Public folder.
AppLimit.CloudComputing.SharpBox.Exceptions.SharpBoxException was unhandled
Message=Couldn't retrieve child elements from the server
Source=AppLimit.CloudComputing.SharpBox
This is what I did ...
I've registered an App with DropBox. This gave me my Consumer information. I used those two pieces of info in the DropBoxTokenIssuer to generate a file (AdvisorExchange.dbtkn) that I'm now using in this part of the application. During the DropBoxTokenIssuer
I entered my Consumer Key and Consumer Secret in the "Application" input fields, and the name of the output file. Then I clicked on "Authorize".
Does this sound like the correct steps?
|
|
|
|
BTW, I'm using SharpBox-1.2.0.542
|
|
|
|
Did you ever find a solution to this problem? I'm running into the exact same problem. Any help would be much appreciated, as I am doubting if SharpBox actually works with Dropbox any longer??
|
|
|
|
Yes ... and no. I was able to access the "Public" folder of the "Shared account" once I created that public folder in the "app" subdirectory my application was looking for. As soon as the user accepts the ability for your app to right into their DropBox
a folder \\Apps\younamehere is created. Once I created a folder named "Public" and put some files in it I could then iterate through them.
What I still haven't gotten the answer to is how to access my own dropbox environment so that I can put files in there and then share them or whatever.
I am able to move files from local PC storage to the shared "Apps" storage. This is what I need to work for what I want to do in the long term.
|
|
|
|
I discovered later that this is due to the permissions granted to your App. The tutorial is a little vague on this subject, but you would only be able to access the '/Public' folder if your app has permissions to access all Dropbox folders. My app was permitted
access only to Apps/[App-Name]/.. and of course there is no folder in here called 'Public'.
I adjusted the code as follows:
Dim myFolder As ICloudDirectoryEntry = dropBoxStorage.GetRoot()
You could also use:
Dim myFolder As ICloudDirectoryEntry = dropBoxStorage.GetFolder("/A Folder in my App")
With this type of permission the file/folder mappings assume your app folder is always the root. The documentation could be a little clearer on this!
|
|
|
|
I can do the GetRoot thing, but that seems like a whole in the DropBox API. If I'm accessing someone else's DropBox I should only be allowed into the area that they gave me permission to get to, e.g., a folder in the App subdirectory. What I'm trying to
figure out, and doesn't seem to work anymore, is how to access my own dropbox and manage / manipulate it through the SharpBox API.
I would also like to see SharpBox / DropBox provide a level of client authorization token caching / streaming. I would like to be able to log in to DropBox, have DropBox provide me with a list of credentialed users for my application, and then be able to
loop through them accessing the files and folders in the App subdirectory that I have access to. It seems from the examples that I might be able to do this, but it also seems that I have to manage the caching of the credentials locally.
|
|