iOS:调用 https://api.dropboxapi.com/2/users/get_current_account 时代码状态为 400,授权良好

iOS: Code Status 400 when calling https://api.dropboxapi.com/2/users/get_current_account with the good Authorization

我尝试调用保管箱 url https://api.dropboxapi.com/2/users/get_current_account 来检查令牌访问是否正常。

它在 Postman 上的效果很好,但在 iOS 上不起作用。

这是 post 人工调用:
在 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)

NSHTTPURL响应:

<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
    );
} }

有什么想法吗?

你应该试试这个:

[[client.usersRoutes getCurrentAccount] setResponseBlock:^(DBUSERSFullAccount * _Nullable result, DBNilObject * _Nullable routeError, DBRequestError * _NullablenetworkError)
                {
                    if (networkError != nil)
                    {
                        NSLog(@"getCurrentAccount failed: network error");
                    }
                    else if (routeError != nil)
                    {
                        NSLog(@"getCurrentAccount failed: route error");
                    }
                    else
                    {
                        NSLog(@"got Dropbox account email: %@", result.email);
                    }
                }];