我使用Dropbox SDK将文件保存到用户的保管箱帐户。
当用户点击“保存到Dropbox”时按钮第一次弹出一个弹出窗口,用户需要登录他们的保管箱帐户。然后,我使用SDK提供的uploadFile
方法将文件上传到其保管箱帐户。但是,第一次,它给了我错误:
DropboxSDK: error making request to /1/files_put/dropbox/sampleFile.pdf - (401) Authentication failed
当我关闭应用并再试一次时,它会成功上传该文件。
可能导致应用程序出现如此奇怪的行为?
答案 0 :(得分:2)
我遇到了同样的问题,事实证明我从viewDidLoad初始化了我的DBRestClient,就像Dropbox文档所说的那样,但由于这种情况发生在Dropbox帐户被链接之前,所以没有正确设置restClient。
通过使用以下方式访问restClient,可以轻松修复重新初始化restClient甚至更好。
-(DBRestClient*)restClient{
if(_restClient == nil){
_restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
[_restClient setDelegate:self];
}
return _restClient;
}
答案 1 :(得分:0)
我收到同样的错误,请在您的应用中使用此代码,希望这会对您有所帮助。
if([[DBSession sharedSession] isLinked])
{
//Do your drop box work here...
}
else
{
//If not linked then start linking here..
[[DBSession sharedSession] linkFromController:self];
}