I have doc file on my dropbox when i access these files from my app i want them to be in pdf techincally i want them to be downloaded in pdf
The API doesn't support converting file formats, but I'll be sure to pass this along as a feature request.
By the way, have you looked at the /get_previews endpoint? Depending on the file type, that can return a PDF version of the file. Try passing your .doc files from your app to /get_previews, and let us know if the returned content suits your needs.
Documentation: https://www.dropbox.com/developers/documentation/http/documentation#files-get_preview
More on file previews for various file types on Dropbox: https://www.dropbox.com/en/help/6
so how can i pass my file the .doc file can you please give me some code example for objective-c
Are you using a particular SDK or library, or are you calling the HTTPS endpoints directly?
i am using dropbox sdk in my ios app
Do you mean the iOS Core SDK? That uses API v1, which does have an equivalent endpoint:
https://www.dropbox.com/developers-v1/core/docs#previews
Unfortunately, that's not implemented in the iOS Core SDK, and we don't have any sample code for doing it. That being the case, you would need to implement it in your app's code.
can you please provide some same code forhttps://www.dropbox.com/developers-v1/core/docs#previewsso i can get a preview.
Unfortunately I don't have any sample code for implementing this endpoint in Objective-C. If you try it and run in to any issues though, feel free to share your code and we'll offer whatever help we can.
NSString * authorizToken = @Bearer <Acess Token>;
NSURL *url = [NSURL URLWithString:[[NSString stringWithFormat:@"https://content.dropboxapi.com/1/previews/auto/%@",dropboxPath ] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ];
NSMutableURLRequest *request =
[NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval:10
];
[request setValue:authorizToken forHTTPHeaderField:@Authorization];
[request setHTTPMethod: @GET];
NSError *requestError = nil;
NSURLResponse *urlResponse = nil;
NSData *response1 =
[NSURLConnection sendSynchronousRequest:request
returningResponse:&urlResponse error:&requestError];
[response1 writeToFile:pdfPath atomically:YES];Error fie not foundwhen i do this
[pMainDelegate.restClient searchPath:@" forKeyword:dropboxData.fileName];it returns that file exits and in the rest client there is no method which helps me in call the https://content.dropboxapi.com/1/previews/auto
What's the value of dropboxPath? Are you sure that "<Acess Token>" is linked to the same app and account as pMainDelegate.restClient?
dropboxpath is /file_name_with_extensionyeah i am sure
from retrieving from this
MPOAuthCredentialConcreteStore *creds = [[DBSession sharedSession] credentialStoreForUserId:[[NSUserDefaults standardUserDefaults] stringForKey:UID]];
NSLog(@\n\naccess token key: %@ secret: %@", creds.accessToken, creds.accessTokenSecret);and when i pass creds.acessToken as <acessToken>
{"error" : "Invalid OAuth2 token."}
and when i pass creds.accessTokenSecret as <acessToken>
can you please elaborate the whole method for getting access token for https://content.dropboxapi.com/1/previews/auto as you can see i have already tried the above method.my scenario is when a user login to app then the access token should get saved in the app
Unfortunately, I don't have a sample implementation of this endpoint in Objective C to share.
Note that the iOS SDK itself uses OAuth 1, so the stored access token from credentialStoreForUserId can't be directly used as an OAuth 2 access token, which is why you're getting that "Invalid OAuth2 token" error.
If you do want to use that stored OAuth 1 access token, there's a blog post that shows how to implement OAuth 1 here:
https://blogs.dropbox.com/developers/2012/07/using-oauth-1-0-with-the-plaintext-signature-method/
(The iOS Core SDK is open source though, so you could alternatively add the source directly and modify the code to add /previews.)
Another option entirely though, which I recommend if your app is still in development mode, is to switch to using the SwiftyDropbox library for API v2, if you can (since it's for Swift):
https://www.dropbox.com/developers/documentation/swift
I tried the whole procedureas documented in
but when i passed the end resulted access token to
the error is still same
i told you i am using objective-c for development and all the issue and dear you just wasted my day
That error message indicates you're still passing up the access token like an OAuth 2 access token (using the "Bearer" syntax), but if you have an OAuth 1 access token, you need to use the OAuth 1 syntax from the blog post I linked to.
For example, I'm not an Objective-C expert, but something like this (modified from your previous code sample):
MPOAuthCredentialConcreteStore *creds = [[DBSession sharedSession] credentialStoreForUserId:UID]; NSString *authorization = [NSString stringWithFormat:@OAuth oauth_version=\1.0\", oauth_signature_method=\"PLAINTEXT\", oauth_consumer_key=\"%@\", oauth_token=\"%@\", oauth_signature=\"%@&%@\", appKey, creds.accessToken, appSecret, creds.accessTokenSecret]; NSString *filePath = @/Testing/Documents/test.docx; NSURL *url = [NSURL URLWithString:[ [NSString stringWithFormat:@"https://content.dropboxapi.com/1/previews/auto/%@", filePath] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding ] ]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10 ]; [request setValue:authorization forHTTPHeaderField:@Authorization]; [request setHTTPMethod: @GET]; NSError *requestError = nil; NSURLResponse *urlResponse = nil; NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&requestError]; NSString *fileName = @test_205881743.pdf; NSString *localDir = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0]; NSString *localFilePath = [localDir stringByAppendingPathComponent:fileName]; [response writeToFile:localFilePath atomically:YES]; NSLog(@%@", localFilePath);
(That doesn't have the error handling implemented though.)
after how much time the Access Token Generated by this blog post will expire
Dropbox API access tokens don't expire.
Users can manually revoke tokens themselves though, e.g. via:
https://www.dropbox.com/account/security
Apps can also revoke access tokens via:
v1: https://www.dropbox.com/developers/core/docs#disable-token
v2: https://www.dropbox.com/developers/documentation/http/documentation#auth-token-revoke