Dropbox SDK 401 Error

2020-06-04 04:15发布

问题:

I am using the Dropbox SDK and I have it set up so the app can only access the /Apps/MyAPP folder. I was testing it out and deleted the folder online. Now when I'm in the app instead of asking to relink dropbox it gives me a 401 error. I don't know why it doesn't display the view. It was working before I deleted the folder(unlinking the app online). Thank you in advance.

PageFlipper[66893:c07] [WARNING] DropboxSDK: error making request to /1/metadata/sandbox - Token is invalid. 2012-08-23 03:10:12.920 PageFlipper[66893:c07] Error loading metadata: Error Domain=dropbox.com Code=401 "The operation couldn’t be completed. (dropbox.com error 401.)" UserInfo=0x23263fe0 {path=/, error=Token is invalid.}

-(IBAction)addDropBox:(id)sender{
    if (![[DBSession sharedSession] isLinked]) {
        [[DBSession sharedSession] linkFromController:[self parentViewController]];
    }
    [[self restClient] loadMetadata:@"/"];
    restClient = nil;
};

回答1:

I had the same problem. In my case the problem was that I did set the restClient before the user was connected. In this case the userId is not set and the token is invalid.

My getter for restClient now looks like this:

- (DBRestClient *)restClient
{
    if (_restClient == nil) {
        if ( [[DBSession sharedSession].userIds count] ) {
            _restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
            _restClient.delegate = self;
        }
    }

    return _restClient;
}


回答2:

I solved the problem by changing the code to the following.

[[DBSession sharedSession] linkFromController:(UINavigationController *)[[appDelegate window] rootViewController]];