![](/img/trans.png)
[英]How to change the Dropbox sync folder location programmatically on OSX
[英]OSX Dropbox Sync API Error - unable to verify link request
在本教程之后实现的Swift中编码。
DBAccountManager是在applicationDidFinishLaunching上的AppDelegate中设置的。
稍后,当用户在我的应用程序中激活保管箱支持时,我正在尝试链接该帐户。 显示窗口面板,我的应用程序正在等待回调。
有时,即使用户登录并接受我也没有链接帐户。
日志显示“ [ERROR]无法验证链接请求”
如果在无法使用的计算机上发生这种情况,则可以重试...如果有效,它就像一个超级按钮,将来我总是直接从库中获取链接帐户,而无需登录窗口。
此错误是什么意思,我该怎么办?
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)
}
....
}
用户单击以激活保管箱时,我班级中的链接:
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)
经过长时间的研究和研究DropBoxSDK,我遇到了相同的问题[ERROR]无法验证链接请求。我得出的结论是,当状态ID与保存在键KDBKLinkNonce上的值不同时,将发生此错误。 每次在新会话上,它都会生成新的状态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
我找到了一些东西,并且由于找到了解决方法,所以即使投寄箱错误也消失了。
问题似乎是NSUserDefaults没有存储任何数据(不在内存中,也不在磁盘上!)。 由于Dropbox使用NSUserDefaults前后检查状态,因此这杀死了整个过程。 恢复NSUserDefaults后,似乎整个保管箱问题都消失了。 OSX NSUserDefaults不起作用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.