I am trying to send a message along with a chart file, but to no avail. This code works well for sending regular message. I am using AFNetworking to do this. The stocktwits endpoint i used:
https://api.stocktwits.com/api/2/messages/create.json
NSURL *url = [NSURL fileURLWithPath:chartFilePath];
NSDictionary *params = @{@"in_reply_to_message_id": inReplyToMsgId, @"chart":url, @"body":msg, @"access_token":oauthtoken};
NSMutableURLRequest *request = [manager.requestSerializer requestWithMethod:@"POST" URLString:reqURL parameters:params];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setResponseSerializer:[AFHTTPResponseSerializer alloc]];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSString *json_string = [[NSString alloc] initWithData:responseObject
encoding:NSUTF8StringEncoding];
NSLog(@"stocktwits: %@", json_string);
}failure:^(AFHTTPRequestOperation *operation, NSError *error){
NSLog(@"Failure: %@", error);
failure(error);
}];
[manager.operationQueue addOperation:operation];
The error message i got:
stocktwits: {"response":{"status":422},"errors":[{"message":"We couldn't recognize the image format. Format must be one of: image/jpeg image/pjpeg image/png image/x-png image/gif"}]}
I have been playing around with other solutions AFNetworking provides sucha as AFMultipartFormData, but also to no avail.
Does someone know what i am missing here?
Thanks!!!