Discuss Dropbox Developer & API
Hi,
We are in the process of adding Dropbox support to our application. Basically this is so users have an option to store attachments in Dropbox (user creates a sales order in our app and wants to attach a Word doc to it for instance). We are using the .Net Dropbox assemblies for this. I have used the dropbox console to create a an app and created an access token for it. I'm then using this code to try to connect -
DropboxClient dbx =
new DropboxClient("XXXXXX");
var result = await dbx.Users.GetCurrentAccountAsync();
var nameSpace = result.RootInfo.RootNamespaceId;
dbx = dbx.WithPathRoot(new PathRoot.Root(nameSpace));
But I get the following error when I the GetCurrentAccount call runs -
Error in call to API function "users/get_current_account":
This API function operates on a single Dropbox account,
but the OAuth 2 access token you provided is for an entire Dropbox Business team.
Since your API app key has team member file access permissions, you can operate on a team member's Dropbox by providing the "Dropbox-API-Select-User" HTTP header or "select_user" URL parameter to specify the exact user <https://www.dropbox.com/developers/documentation/http/teams>.
I have not been able to find a C# sample that works yet for this. Is there another way or what is the recommended way of doing this? I would prefer to not have each user having to authenticate each time they want to access an attachment through our application.
I have cross-posted this in the API Support forum as well in case it gets more visibility there.
Thanks
This error message indicates that the access token you're using is for a "Dropbox Business API" app, which connects to entire Dropbox Business teams, but the method you're trying to use is for specific Dropbox accounts.
If you want any kind of Dropbox account (Business or not) to be able to connect to your app, you should instead register a "Dropbox API" app. That kind of app needs to be authorized by each end-user, at which point the app receives an access token for that user's account and can call methods like GetCurrentAccountAsync without additional configuration.
Alternatively, if you only want to connect Business accounts, you can use your "Dropbox Business API" app registration. That kind of app only need to be authorized by a team admin, at which point the app receives an access token for that entire team. Your app would then need to additionally specify which team member to operate on when making an account-specific call such as GetCurrentAccountAsync. You can do so by first making a DropboxTeamClient object and calling DropboxTeamClient.AsMember with the relevant team member ID to get a DropboxClient for that team member.
I have been trying to use the AsMember method and it seems to always throw this error when I use it - "Invalid select user id format"
DropboxTeamClient teamClient = new DropboxTeamClient(OAUTHTOKEN);
var results = await teamClient.Team.MembersListAsync();
string memberID = string.Empty;
foreach (var member in results.Members)
{
if (member.Profile.Email.Equals("tcash@mac.com", StringComparison.OrdinalIgnoreCase))
{
memberID = member.Profile.AccountId;
if (memberID.StartsWith("dbid:", StringComparison.OrdinalIgnoreCase))
{
memberID = memberID.Substring(5);
}
break;
}
}
var dbx = teamClient.AsMember($"dbmid:{memberID}");
The member ID I get from the member profile is in the format of "dbid:XXXXXX", while the code I have found in the forms seems to want to set it as "dbmid:XXXXXX". I've tried both styles and neither worked.
The AsMember method expects the "team member ID", which is the ID that starts with "dbmid:". Dropbox supplies these values directly, and you should not attempt to modify them.
The team member ID is available as MemberProfile.TeamMemberId (not MemberProfile.AccountId).
Ok, so I did try using that value and it gave me the same error.
Can your share your current code for that? I just modified your earlier code and it worked fine for me:
DropboxTeamClient teamClient = new DropboxTeamClient(ACCESS_TOKEN); var results = await teamClient.Team.MembersListAsync(); string memberID = string.Empty; foreach (var member in results.Members) { if (member.Profile.Email.Equals(EMAIL_ADDRESS, StringComparison.OrdinalIgnoreCase)) { memberID = member.Profile.TeamMemberId; break; } } //or use MembersGetInfoAsync to look up a specific member directly var dbx = teamClient.AsMember(memberID); var result = await dbx.Users.GetCurrentAccountAsync();
Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on X or Facebook.
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!