2012-07-17 278 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