【发布时间】:2015-06-15 20:24:20
【问题描述】:
我想通过我的 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);
}
【问题讨论】:
标签: ios objective-c twitter twitter-rest-api