我想从我的 iOS 应用程序中将照片发布到 Twitter。我可以在没有媒体的情况下发布推文,但是当我尝试附加媒体时会引发错误。
我正在关注 twitter 文档,据此首先我需要将媒体上传到https://upload.twitter.com/1.1/media/upload.json,然后我将能够使用 media-id 将其与推文一起附加。
这是我上传媒体的代码。
应用程序在 URLRequestWithMedthod 调用时崩溃。
帮我解决问题。
UIImage *image = [UIImage imageNamed:@"shareit.png"];
NSData *imageData = UIImageJPEGRepresentation(image, 0.7);
NSString *statusesShowEndpoint = @"https://upload.twitter.com/1.1/media/upload.json";
NSDictionary *params = @{@"media" : imageData};
NSError *clientError;
NSURLRequest *request = [[[Twitter sharedInstance] APIClient]
URLRequestWithMethod:@"POST"
URL:statusesShowEndpoint
parameters:params
error:&clientError];
if (request) {
[[[Twitter sharedInstance] APIClient]
sendTwitterRequest:request
completion:^(NSURLResponse *response,
NSData *data,
NSError *connectionError) {
if (data) {
// handle the response data e.g.
NSError *jsonError;
NSDictionary *json = [NSJSONSerialization
JSONObjectWithData:data
options:0
error:&jsonError];
NSLog(@"%@",json);
}
else {
NSLog(@"Error: %@", connectionError);
}
}];
}
else {
NSLog(@"Error: %@", clientError);
}