以下のAPIを試しているのですが、"invalid authentication"と言うエラーが出てしまい、どうしてもうまくいきません。
https://coincheck.com/ja/documents/exchange/api#auth
何かおかしい箇所などがありますでしょうか、以下実際のコードになります。
- (void)httpRequest:(NSString*)actionType priceString:(NSString*)priceString
{
NSInteger unixtime = [[NSDate date] timeIntervalSince1970];
NSURLComponents *components = [NSURLComponents componentsWithString:@"https://coincheck.com/api/exchange/orders"];
NSURLQueryItem *pair = [NSURLQueryItem queryItemWithName:@"pair" value:@"btc_jpy"];
NSURLQueryItem *order_type = [NSURLQueryItem queryItemWithName:@"order_type" value:actionType];
NSURLQueryItem *currency_pair = [NSURLQueryItem queryItemWithName:@"rate" value:priceString];
NSURLQueryItem *amount = [NSURLQueryItem queryItemWithName:@"amount" value:BitCoinPrice];
components.queryItems = @[pair,order_type,currency_pair,amount];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; NSString *url = @"https://coincheck.com/api/exchange/orders/"; NSMutableURLRequest *req = [[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:url parameters:nil error:nil]; [req setValue:@"xxxxxxxxxx" forHTTPHeaderField:@"ACCESS-KEY"]; NSString *unixTimes =[NSString stringWithFormat:@"%ld",(long)unixtime]; [req setValue:unixTimes forHTTPHeaderField:@"ACCESS-NONCE"]; NSString *strx = [NSString stringWithFormat:@"%@%@%@", unixTimes, url, components.query]; [req setValue:[self hmac256:strx withKey:@"xxxxxxxxxxxxx"] forHTTPHeaderField:@"ACCESS-SIGNATURE"];
// NSData *httpBodyData = [components.query dataUsingEncoding:NSUTF8StringEncoding];
// [req setHTTPBody:httpBodyData];
//
[[manager dataTaskWithRequest:req completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { if (!error) { NSLog(@"Reply JSON: %@", responseObject); if ([responseObject isKindOfClass:[NSDictionary class]]) { //blah blah } } else { NSLog(@"Error: %@, %@, %@", error, response, responseObject); } }] resume];
}
宜しくお願いします。
あなたの回答
tips
プレビュー