FatSecret Rest API抛出错误对象引用未设置为对象的实例

时间:2017-07-22 21:51:17

标签: ios objective-c rest

我正在尝试实现FatSecret REST API,但在评估Food.search获取错误时,无法理解服务器错误的App实现错误。

请求网址:GET

 NSString *endpoint= @"https://platform.fatsecret.com/rest/server.api?&format=json&language=en&max_results=50&method=foods.search&oauth_consumer_key=9d*********&oauth_nonce=52A2E&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1500756883&oauth_version=1.0&page_number=0&region=US&search_expression=r&oauth_signature=CvB%2F52z7c2T7******%3D"

 NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];

    NSURL *url = [NSURL URLWithString:endpoint];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        //
        if (data) {
            NSHTTPURLResponse * httpResponse  = (NSHTTPURLResponse*)response;
            NSInteger statusCode = httpResponse.statusCode;
            if (statusCode == 200) {
                //PERFORM YOUR OPERATIONS
                NSString *json = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
                NSLog(@"%@", json);
            }
        }else if (error)
        {
            NSLog(@"Errorrrrrrr....");
        }

    }];
    [dataTask resume];

响应:

{ "error": {"code": 1, "message": "An unknown error occurred: Object reference not set to an instance of an object." }}

请帮忙,让我知道我做错了什么。

提前致谢

0 个答案:

没有答案