Forum Discussion

Crypto C.'s avatar
Crypto C.
New member | Level 1
11 years ago

OAuth 2.0 - IOS API V 2.0

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

Replies have been turned off for this discussion
  • SGS E.'s avatar
    SGS E.
    New member | Level 1
    11 years ago

    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's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    11 years ago

    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.'s avatar
    SGS E.
    New member | Level 1
    11 years ago

    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 :(

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

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!