2012-07-17 199 views

回答

3

这是可能的,但建议使用而不是

警告:这将允许任何人访问读/写您的保管箱帐户(或应用程序文件夹,取决于您允许的访问权限)。

我想你要设置你的应用程序了作为入门指南建议: https://www.dropbox.com/developers/core/authentication#ios

这里的工作原理是:一旦你登录到Dropbox的,你将被重定向回您的应用程序。 Dropbox的做到这一点通过让你注册一个URL方案,并利用以下的AppDelegate方法:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url; 

的Dropbox经过oauth_tokenoauth_token_secretuidurl参数。然后,将保存这些供以后使用当您使用的DBSession以下方法API调用:

- (BOOL)handleOpenURL:(NSURL *)url; 

所以你可以做什么它创建一个使用相同App KeySecret的应用程序。

测试程序

DBSession* dbSession = 
    [[[DBSession alloc] 
     initWithAppKey:@"APP_KEY" 
     appSecret:@"APP_SECRET" 
     root:ACCESS_TYPE] // either kDBRootAppFolder or kDBRootDropbox 
    autorelease]; 
[DBSession setSharedSession:dbSession]; 

请求授权

if (![[DBSession sharedSession] isLinked]) { 
    [[DBSession sharedSession] linkFromController:yourRootController]; 
} 

然后添加AppDelegate的方法来接收授权url

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { 
    if ([[DBSession sharedSession] handleOpenURL:url]) { 
     if ([[DBSession sharedSession] isLinked]) { 
      NSLog(@"App linked successfully! url: %@", url); 
      // At this point you can start making API calls 
     } 
     return YES; 
    } 
    // Add whatever other url handling code your app requires here 
    return NO; 
} 

这将记录url机智h授权令牌。复制,然后在您的生产应用程序(您配置DBSession后右)只是这样做(替换为你之前复制的一个字符串):

生产APP

DBSession* dbSession = 
    [[[DBSession alloc] 
     initWithAppKey:@"APP_KEY" 
     appSecret:@"APP_SECRET" 
     root:ACCESS_TYPE] // either kDBRootAppFolder or kDBRootDropbox 
    autorelease]; 
[DBSession setSharedSession:dbSession]; 

if (![[DBSession sharedSession] isLinked]) { 
    [[DBSession sharedSession] handleOpenURL:[NSURL URLWithString:@"db-APP_KEY://1/connect?oauth_token=********&oauth_token_secret=********&uid=********"]]; 
} 

这将自动链接将DBSession添加到您的Dropbox帐户。

您可以通过拨打这只是你之前授权测试:

[[DBSession sharedSession] unlinkAll]; 

另一个警告 我可以只下载你的应用程序,解压授权令牌,然后开始做所有的读/写API我想要的电话。这是完全不安全的,应该只被视为教育活动。

+0

我按照你的步骤,但它给了我[错误]无法验证链接请求错误。 sdk隐私被更改了吗?我想做同样的功能。帮助将被appriciated。 – 2014-12-18 09:20:35