macos - OSX Dropbox Sync API 错误 - 无法验证链接请求

标签 macos swift dropbox

我在教程之后用 Swift 编码。

DBAccountManager 在 applicationDidFinishLaunching 上的 AppDelegate 中设置。

稍后,当用户在我的应用程序中激活 dropbox 支持时,我正在尝试链接该帐户。 显示窗口面板,我的应用程序正在等待回调。

有时我没有得到链接的帐户,即使用户登录并接受。

日志说 [错误] 无法验证链接请求”

当这发生在一台机器上是行不通的,你可以重试再重试... 如果它有效,它就像一个魅力,将来我总是直接从图书馆获得链接的帐户,而无需登录窗口。

这个错误是什么意思,我该怎么办?

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)
    }

    ....
 }

我类(class)中的链接,当用户点击激活保管箱时:

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
}

这是完整的日志,应用程序没有做任何其他事情:

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)

最佳答案

我有同样的问题[ERROR] unable to verify link request 经过长时间的研究和研究 DropBoxSDK 我得出的结论是当状态 ID 与保存在键 KDBKLinkNonce。每次在新 session 中它都会生成新的状态 ID。请参阅下面的 [[DBSession sharedSession] handleOpenURL:url] 方法的代码。

- (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; }

如需进一步引用,请查看此链接 dropbox-sdk-ios

关于macos - OSX Dropbox Sync API 错误 - 无法验证链接请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28605843/

相关文章:

ios - 将音频文件保存到用户友好的位置 swift 3 avfoundation

linux - 开源保管箱类型的软件?

java - 如何在 Mac OS X 上获取文件类型?

swift - 将非泛型扩展为泛型

python - 如何在 macOS 上升级到 python 3.6.4?

ios - 有没有办法更改更多导航编辑弹出模式中的导航栏色调颜色?

python - 通过代理通过 python 连接到保管箱

database - 使用 OneDrive 或 Dropbox 作为数据库

C文件无法编译

python - noob,但是我在我的mac上安装了python 2.7.5,如何我 "target"那个而不是内置的2.7.2?