cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Share your feedback on the Document Scanning Experience in the Dropbox App right here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

OAuth 2.0 - IOS API V 2.0

OAuth 2.0 - IOS API V 2.0

Crypto C.
New member | Level 1

Hello ! 

I use the the version API dropbox 1.0 for my app IOS, the new 2.0 is only swift and i can not use it because my app use only object-c.

So now i use API 1.0 for generate autentication DBSession restClient etc then use "https://api.dropboxapi.com/1/oauth2/token_from_oauth1" for access_token and call via HTTP the new api.dropboxapi.com/2. 

This method works correctly, my question is, if this method is a good way to take advantage of the new API V2 ?

thanks

m.

16 Replies 16

Crypto C.
New member | Level 1

ok, 

add :

[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

and now it's ok ....

good work.

SGS E.
New member | Level 1

Hi, Could you please give some instruction how to get acessToken v2 from accessToken v1?

i know this API "https://api.dropboxapi.com/1/oauth2/token_from_oauth1 but dont know how to pass the parameters. 

i'm using ios sdk

Crypto C.
New member | Level 1

Hi SGS E. none parameters is required, post 

"https://api.dropboxapi.com/1/oauth2/token_from_oauth1" method "POST" with 

Authorization OAuth 1.0 and return access_token OAuth 2.0

very easy.

bye

Greg-DB
Dropbox Staff

That's correct, that endpoint requires OAuth 1 signing. This blog post, specifically step 4, may be helpful:

https://blogs.dropbox.com/developers/2012/07/using-oauth-1-0-with-the-plaintext-signature-method/

SGS E.
New member | Level 1

Hi,

I'm sorry but i still cant do it.

Now what i have is DBSession restClien or something like that.Is there anyway to get accesssToken v2 from resclient ?

Could you please give some sample code in your project ?

here is my code but it doesnt work well

 

MPOAuthCredentialConcreteStore* credential = [[DBSession sharedSession] credentialStoreForUserId:[info userId]];

    AFHTTPSessionManager* manager = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:BASE_URL]];

    manager.responseSerializer = [AFHTTPResponseSerializer serializer];

    manager.requestSerializer = [AFHTTPRequestSerializer serializer];

    [manager.requestSerializer setValue:@"OAuth" forHTTPHeaderField:@"Authorization"];

    [manager.requestSerializer setValue:@"1.0" forHTTPHeaderField:@"oauth_version"];

    [manager.requestSerializer setValue:@"PLAINTEXT" forHTTPHeaderField:@"oauth_signature_method"];

    [manager.requestSerializer setValue:APP_KEY_DB forHTTPHeaderField:@"oauth_consumer_key"];

    [manager.requestSerializer setValue:credential.accessToken forHTTPHeaderField:@"oauth_token"];

    [manager.requestSerializer setValue:[NSString stringWithFormat:@"%@&%@",credential.requestTokenSecret,credential.accessTokenSecret] forHTTPHeaderField:@"oauth_signature"];

   [manager POST:@"https://api.dropboxapi.com/1/oauth2/token_from_oauth1" parameters:@{} success:^(NSURLSessionDataTask *task, id responseObject) {

   } failure:^(NSURLSessionDataTask *task, NSError *error) {

   }];

 

//It show error

Code=-1011 "Request failed: bad request (400)"

Greg-DB
Dropbox Staff

I don't believe we have any sample code for this specifically in Objective-C unfortunately.

Looking at your code, it seems you are setting all of the OAuth parameters as individual parameters, when they should just be together in the one "Authorization" header, as shown in the blog post I linked to.

SGS E.
New member | Level 1

yah, you are right , after change the OAuth parameters as the one it works like a charm !

Thank you very much.

btw,dropbox sdk is great but the ios' sdk and its document is quite out of date :disappointed_face:

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    SGS E. New member | Level 1
  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Crypto C. New member | Level 1
What do Dropbox user levels mean?