iOS: код статуса 400 при звонке https://api.dropboxapi.com/2/users/get_current_account с хорошей авторизацией - PullRequest
0 голосов
/ 09 июля 2019

Я попытался вызвать URL-адрес dropbox https://api.dropboxapi.com/2/users/get_current_account, чтобы проверить, хорош ли доступ к токену.

Это работает как шарм на Почтальоне, но не работает на iOS.

Вот этот звонок:
В заголовках:
Headers В теле:
Body

Этот код:

            DBUserClient *client = [[DBUserClient alloc] initWithAccessToken:@"-sWPE_Fqxxxxxxxxxxxxxxxxxxxfdhgfdf82mk"];

            [[client.usersRoutes.getCurrentAccount] response:^(DBUSERSFullAccount *account, DBNilObject *_, DBRequestError *error) {
                if (account) {
                    NSLog(@"%@", account);
                } else if (error) {
                    NSLog(@"%@", error);
                }
            }];

(Не работает, ответ функции: ^ не распознается.

А это мой код:

DBUserClient *client = [[DBUserClient alloc] initWithAccessToken:@"-sWPE_FqvVAAxxxxxxxxxakjhdazhdzatEQGUd82mk"];


                NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString: @"https://api.dropboxapi.com/2/users/get_current_account"]];

                [urlRequest setHTTPMethod:@"POST"];

                NSData *postData = [NSData new];
                [urlRequest setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[postData length]] forHTTPHeaderField:@"Content-Length"];
                [urlRequest setHTTPBody:postData];


                NSURLSession *session = [NSURLSession sharedSession];
                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:urlRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
                    NSLog(@"code status: %ld", (long)httpResponse.statusCode);
                    if (httpResponse.statusCode == 200)
                    {
                        NSError *parseError = nil;
                        NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];
                        NSLog(@"The response is - %@",responseDictionary);
                        NSInteger success = [[responseDictionary objectForKey:@"success"] integerValue];
                        if(success == 1)
                        {
                            NSLog(@"Login SUCCESS");
                        }
                        else
                        {
                            NSLog(@"Login FAILURE");
                        }
                    }
                    else
                    {
                        NSLog(@"Error");
                    }
                }];
                [dataTask resume];

(тоже не работает, есть код состояния 400)

NSHTTPURLResponse:

<NSHTTPURLResponse: 0x281fd3c20> { URL: https://api.dropboxapi.com/2/users/get_current_account } { Status Code: 400, Headers {
    "Content-Disposition" =     (
        "attachment; filename='error'"
    );
    "Content-Type" =     (
        "text/plain; charset=utf-8"
    );
    Date =     (
        "Wed, 10 Jul 2019 08:18:40 GMT"
    );
    Server =     (
        nginx
    );
    "content-security-policy" =     (
        "sandbox; frame-ancestors 'none'"
    );
    "x-content-type-options" =     (
        nosniff
    );
    "x-dropbox-request-id" =     (
        17d523a27f864ce88531b122b4bec71d
    );
    "x-frame-options" =     (
        DENY
    );
} }

Есть идеи?

...