Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
Currently nothing happens when I run my code.
This is how I am setting the up client. I did not put the client set up in my viewDidLoad
method because this class will never be shown it just handles server side actions.
(instancetype)initWithClient
{
self = [super init];
if (self) {
self.restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
self.restClient.delegate = self;
}
return self;
}
This is how I make the API call to upload
(void)uploadToDropBox:(UIImage *)img
{
NSLog(@"Entered the DB upload method");
NSArray *directories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,
YES);
NSString *documentDirectory = [directories firstObject];
NSString *imagePath = [documentDirectory stringByAppendingPathComponent:@"cardImage"];
NSString *destDir = @"Apps/BirthdayScrapbook";
NSLog(@"Just about to execute the upload method");
NSData *imageData = UIImagePNGRepresentation(img);
[imageData writeToFile:imagePath atomically: YES];
[self.restClient uploadFile:@"cardImage" toPath:destDir withParentRev:nil fromPath:imagePath];
NSLog(@"Executed the DB upload method");
[self sendBDayCard];
}
I think I am going about it wrong. I know what my access token is, but I don't know what to do with it nor where to put it. There is a client init method that takes in the userID
, but I don't know where to find my accounts userID
. Can someone give some direction with this?
The nonce should just be any random string, which should only be used once. You can get the current timestamp however you wish.
Also, for what it's worth, if it saves you some trouble, since you just need the one account, I believe you can supply any arbitrary string for userID
in the updateAccessToken
method. (I can't promise that will always work though.)
Finally, I recommend getting your account linked properly first, but there are a few things that might cause your delegate methods to not be called:
nil
or is being released (e.g., by ARC) prematurely.Be sure to check your console for any errors though.
How do I go about making sure that my account is linked properly? I am using the Facebook SDK in my app as well. Do you think it is a problem that I had to hack together (BOOL)application:(UIApplication *)app openURL:(NSURL *)url sourceApplication:(NSString *)source annotation:(id)annotation method in order to please both API's like this
return [FBAppCall handleOpenURL:url
sourceApplication:sourceApplication
withSession:[PFFacebookUtils session]] && [[DBSession sharedSession] handleOpenURL:url] && [[DBSession sharedSession] isLinked];
}
Instead of doing this like in the tutorial
- (BOOL)application:(UIApplication \*)app openURL:(NSURL \*)url
sourceApplication:(NSString \*)source annotation:(id)annotation {
if ([[DBSession sharedSession] handleOpenURL:url]) {
if ([[DBSession sharedSession] isLinked]) {
NSLog(@"App linked successfully!");
// At this point you can start making API calls
}
return YES;
}
// Add whatever other url handling code your app requires here
return NO;
}
In addition, what would be considered calling in the background thread as oppose to calling in the main thread?
In my app delegate method I checked to see if the session was linked and from my test the logs states that my session is linked.
if ([[DBSession sharedSession] isLinked]) {
NSLog(@"The session IS linked");
} else {
NSLog(@"The session is not linked");
}
I have checked my app console and is says that one users is connected to the app and it also says that I made one API call yesterday. However I don't see the test image that I wast trying to upload to dropbox. I am wondering if I am uploading the file incorrectly. This is my upload method
{
UIImage *testPic = [UIImage imageNamed:@"IMG_0005.jpg"];
NSArray *directories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,
YES);
NSString *documentDirectory = [directories firstObject];
NSString *imagePath = [documentDirectory stringByAppendingPathComponent:@"cardImage"];
NSString *destDir = @"/";
NSData *imageData = UIImagePNGRepresentation(testPic);
[imageData writeToFile:imagePath atomically: YES];
[self.restClient uploadFile:@"cardImage" toPath:destDir withParentRev:nil fromPath:imagePath];
[self sendBDayCard];
}
You may want to check that [UIImage imageNamed:@"IMG\_0005.jpg"]
exists in your project and that it is getting saved to your local filesystem correctly. Another thing to check would be that your uploadToDropBox:
method is getting called at all.
Also, have you implemented the uploadedFile
and uploadFileFailedWithError
delegates as described in https://www.dropbox.com/developers/core/start/ios#uploading?
If the error delegate is called, you should be able to see exactly what failed.
Hello
I'm trying out the sdk using a generated access token but I keep getting an "Access token not found" error even though the token works fine in android.
Here is my case (swift):
let dropboxSession = DBSession(appKey: DB_KEY, appSecret: DB_SECRET, root: kDBRootAppFolder)
dropboxSession.updateAccessToken(DB_ACCESS_TOKEN, accessTokenSecret: DB_ACCESS_TOKEN_SECRET, forUserId: DB_USER_ID)
DBSession.setSharedSession(dropboxSession)
So I'd appreciate to know what "DB_ACCESS_TOKEN_SECRET" should be since the generated token is a single string?
Mitchel, your issue doesn't seem related to the one in this thread. Please start a new thread.
Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!