1

我正在从 iOS 客户端向 Asana 发送 API 调用,并得到一个标题为:Asana - Unsupported Browser 的 HTML 页面,它告诉我调用的方式有问题。

我的API调用代码如下:

客户端设置在这里:

- (id) initHTTPClient {
    self = [super initWithBaseURL:[NSURL URLWithString:ASANA_BASE_URL]];

    if (self) {
        [self registerHTTPOperationClass:[AFJSONRequestOperation class]];
        [self setDefaultHeader:@"Accept" value:@"application/json"];
        [self setParameterEncoding:AFJSONParameterEncoding];
        [self setAuthorizationHeaderWithUsername:ASANA_API_KEY password:[NSString string]];
    }

    return self;
}

API调用在这里构造:

- (void) getCurrentUser {

    NSDictionary *parameters = [NSDictionary dictionary];

    NSMutableURLRequest *request = [self requestWithMethod:@"GET" path:@"/users/me.json" parameters:parameters];

    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSError *error;
        NSDictionary *response = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:&error];
        NSLog(@"Success, here's what we got: %@",response);

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Failure, error: %@",error.debugDescription);
    }];

    [operation start];
}
4

0 回答 0