0

Coded in Swift I implemented after the Tutorial.

DBAccountManager is setup in AppDelegate on applicationDidFinishLaunching.

Later, when the user activates dropbox support in my application I'm trying to link the account. The Window Panel is displayed and my application is waiting for the callback.

Sometimes I do not get a linked account, even the user logs in and accepts.

The Log says "[ERROR] unable to verify link request"

When this occurs on a machine it wont't work, you can retry and retry... if it worked, it works like a charm and in future I always get the linked account directly from the library without the login window.

What does this error mean and what can I do?

AppDelegate:

func applicationDidFinishLaunching(aNotification: NSNotification) {
    // Dropbox API Key & Secret
    let _appKey = "------"
    let _appSecret = "------"

    // Accountmanager
    if (DBAccountManager.sharedManager() == nil)
    {
        let accountManager = DBAccountManager(appKey: _appKey, secret: _appSecret)
        DBAccountManager.setSharedManager(accountManager)
    }

    ....
 }

The linking in my class, when user clicked to activate dropbox:

internal func __start(parentWindow:NSWindow?, callback:((Bool) -> Void))
{
    let am = DBAccountManager.sharedManager()        
    if am == nil
    {
        NSLog("Dropbox not available!")
        callback!(false)
        return           
    }
    // link account
    let linkedAccount = am!.linkedAccount

    if (linkedAccount != nil)
    {
        // Already linked
        DLog("Dropbox link found.")
        let fileSystem = DBFilesystem(account: linkedAccount!)
        DBFilesystem.setSharedFilesystem(fileSystem)
        callback(true)
    }
    else
    {
        // link with window must be in mainthread
        dispatch_async(dispatch_get_main_queue())
        {
            am!.linkFromWindow(parentWindow) {
                account in

                if (account != nil)
                {
                    DLog("Dropbox linked")
                    let fileSystem = DBFilesystem(account: account!)
                    DBFilesystem.setSharedFilesystem(fileSystem)
                    callback(true)
                }
                else
                {
                    DLog("NOT LINKED (Dropbox)")
                    callback(false)
                } // if - else account
            } // accountmanager block
        } // dispatchblock main
    } // if - else linkedaccount
}

Here the full log, the app is not doing anything else:

2015-02-23 10:25:39.443 TestApp[39226:30958267] Dropbox init
<<<< MediaValidator >>>> mv_ValidateRFC4281CodecId: Unrecognized codec 1.(null). Failed codec specific check.
<<<< MediaValidator >>>> mv_LookupCodecSupport: Unrecognized codec 1
[10:25:40.979] mv_LowLevelCheckIfVideoPlayableUsingDecoder signalled err=-12956 (kFigMediaValidatorError_VideoCodecNotSupported) (video codec 1) at  line 1851
<<<< MediaValidator >>>> mv_TestCodecSupportUsingDecoders: Unrecognized codec 1
<<<< MediaValidator >>>> mv_ValidateRFC4281CodecId: Unrecognized codec 1.(null). Failed codec specific check.
<<<< MediaValidator >>>> mv_LookupCodecSupport: Unrecognized codec 1
[10:25:40.979] mv_LowLevelCheckIfVideoPlayableUsingDecoder signalled err=-12956 (kFigMediaValidatorError_VideoCodecNotSupported) (video codec 1) at  line 1851
<<<< MediaValidator >>>> mv_TestCodecSupportUsingDecoders: Unrecognized codec 1
2015-02-23 10:25:43.873 TestApp[39226:30958267] [ERROR] unable to verify link request
2015-02-23 10:25:43.879 TestApp[39226:30958267] NOT LINKED (Dropbox)
6
  • [Cross-linking for reference: dropboxforum.com/hc/communities/public/questions/… ]
    – Greg
    Commented Feb 19, 2015 at 16:33
  • Can you post the rest of the relevant code? E.g., where you call linkFromController and handleOpenURL? The error is indicating that it was unable to verify the state value in the returned request to link the account. The value is compared against a copy stored in NSUserDefaults.
    – Greg
    Commented Feb 19, 2015 at 16:35
  • There is nor more code. You use linkFromWindow on OSX. linkFromController is iOS? - only the lines getting the Shared AccountManager from the applicationDidFinish Launching. Commented Feb 20, 2015 at 9:00
  • added all code used now. All the rest is in the dropbox.framework I included. Just have some header files. - This code is working on my dev machine at the moment.But I had this error and some other testers have the error all the time. Commented Feb 20, 2015 at 9:07
  • Right, my apologies, I was thinking of the iOS Core SDK. Anyway, thanks for adding that additional code. Nothing looks clearly wrong here. The meaning of the error message is the same though. I.e., the state nonce value previously stored in NSUserDefaults doesn't match the state value returned with the link attempt. Is it possible linkFromWindow is getting called more than once, or that something is interfering with NSUserDefaults? In any case, if you reproduce this with the latest version of the SDK, please report the steps here: dropbox.com/developers/contact
    – Greg
    Commented Feb 20, 2015 at 16:33

2 Answers 2

2

I have same issue [ERROR] unable to verify link request after long research and studying the DropBoxSDK I come to the point that this error occurs when state ID is different from value saved at key KDBKLinkNonce. Every time at new Session it generates new state ID. See below code of [[DBSession sharedSession] handleOpenURL:url] method.

- (BOOL)handleOpenURL:(NSURL *)url {
NSString *expected = [NSString stringWithFormat:@"%@://%@/", [self appScheme], kDBDropboxAPIVersion];
if (![[url absoluteString] hasPrefix:expected]) {
    return NO;
}

NSArray *components = [[url path] pathComponents];
NSString *methodName = [components count] > 1 ? [components objectAtIndex:1] : nil;

if ([methodName isEqual:@"connect"]) {
    NSDictionary *params = [DBSession parseURLParams:[url query]];
    NSString *token = [params objectForKey:@"oauth_token"];
    NSString *secret = [params objectForKey:@"oauth_token_secret"];
    NSString *userId = [params objectForKey:@"uid"];

    NSString *state = [params objectForKey:@"state"];
    NSString *nonce = [[NSUserDefaults standardUserDefaults] objectForKey:kDBLinkNonce];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:kDBLinkNonce];
    [[NSUserDefaults standardUserDefaults] synchronize];
    if (![nonce isEqual:state]) {
        DBLogError(@"unable to verify link request");
        return NO;
    }

    [self updateAccessToken:token accessTokenSecret:secret forUserId:userId];
} else if ([methodName isEqual:@"cancel"]) {
    DBLogInfo(@"DropboxSDK: user cancelled Dropbox link");
}

return YES; }

For further reference please check this link dropbox-sdk-ios

0

I found something and since I found a fix for that, even the dropbox error is gone.

The problem seems to be, that NSUserDefaults did not store any data (not in memory and not on disk!). Since Dropbox uses NSUserDefaults to check the state before and after, this killed the whole process. With getting the NSUserDefaults back working it seems the whole dropbox problem was gone. OSX NSUserDefaults not Working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.