Auto Login Dropbox account on Core Api without Login Prompt

后端 未结 2 2282
天涯浪人
天涯浪人 2020-11-29 14:11

I am new to iOs development and I\'m creating an app that uses my own dropbox account. I want my app to automatically login to my account to be able to modify & add file

2条回答
  •  感情败类
    2020-11-29 14:25

    Sorry, I couldn't follow the accepted answer and Greg seems very reluctant to provide example code since Dropbox doesn't recommend using a secret key in this way. For anyone who needs a quick solution to (for example) uploading zip files into a single dropbox account WITHOUT using what I consider the rather opaque dropbox iOS SDK API, the following works (DropboxOAuthKey is the secret key that you press the button to generate in the app console):

    NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
    sessionConfiguration.HTTPAdditionalHeaders = @{
                                                           @"Authorization" : [NSString stringWithFormat:@"Bearer %@", DropboxOAuthKey],
                                                           @"Content-Type"  : @"application/zip"
                                                           };
    
    NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: sessionConfiguration delegate: self delegateQueue: [NSOperationQueue mainQueue]];
    self.request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api-content.dropbox.com/1/files_put/auto/%@?overwrite=false",fileName]]];
    [self.request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
    NSData *data = [[NSFileManager defaultManager] contentsAtPath:zippedPath];
    [self.request setHTTPMethod:@"PUT"];
    [self.request setHTTPBody:data];
    [self.request setTimeoutInterval:1000];
    
    NSURLSessionDataTask *doDataTask = [defaultSession dataTaskWithRequest:self.request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                if (!error){
                    NSLog(@"WORKED!!!!");
                } else {
                    NSLog(@"ERROR: %@", error);
                }
            }];
    
    [doDataTask resume];
    

提交回复
热议问题