如何在iOS中使用SLRequest通过私人推文发布图像?
我有一个问题,我有一些追随者,我想发送一个直接的信息与形象的所有追随者,但我没有办法做到这一点 我研究了整个文档,但找不到这样做的方法 我的代码在这里:如何在iOS中使用SLRequest通过私人推文发布图像?,ios,post,twitter,slrequest,Ios,Post,Twitter,Slrequest,我有一个问题,我有一些追随者,我想发送一个直接的信息与形象的所有追随者,但我没有办法做到这一点 我研究了整个文档,但找不到这样做的方法 我的代码在这里: NSString *strUrl = @"https://api.twitter.com/1.1/direct_messages/new.json"; NSURL *url = [NSURL URLWithString:strUrl]; strUrl = nil; NSMutableDictionary *param
NSString *strUrl = @"https://api.twitter.com/1.1/direct_messages/new.json";
NSURL *url = [NSURL URLWithString:strUrl];
strUrl = nil;
NSMutableDictionary *parameters = [NSMutableDictionary new];
[parameters setValue:@"name" forKey:@"screen_name"];
[parameters setValue:@"123456" forKey:@"user_id"];
[parameters setValue:@"sending text" forKey:@"text"];
// Creating a request.
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:url
parameters:parameters];
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.greenuplawnandsprinklers.com/uploads/design_sample_landscape.jpg"]];
[request addMultipartData:imageData
withName:@"media[]"
type:@"image/jpeg"
filename:@"image.jpg"];
imageData = nil;
[request setAccount:twitAccount];
url = nil;
parameters = nil;
// Perform the request.
[request performRequestWithHandler:^(NSData *responseData,NSHTTPURLResponse *urlResponse,NSError *error)
{
dispatch_async(dispatch_get_main_queue(), ^{
// Check if we reached the rate limit.
if ([urlResponse statusCode] == 429)
{
NSLog(@"Rate limit reached");
return;
}
if(LOGS_ON) NSLog(@"TwitterFriendModel-->shareMagazineTitle-->error = %@",error);
// Check if there is some response data.
if (responseData)
{
NSError *error = nil;
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
NSLog(@"dictionary = %@",dictionary);
dictionary = nil;
}
});
}];
}
我在stackoverflow上看到了所有其他类似的问题/答案,但我没有办法用图像直接向追随者发送消息
请不要把这个问题看成是重复的,试着解决我的问题。我将感谢您提供的每一条线索。这是我完成这项任务的代码,它对我很有用。。希望对你也有帮助
NSDictionary *message = @{@"status": messagetext};
NSURL *requestURL = [NSURL
URLWithString:@"https://upload.twitter.com/1/statuses/update_with_media.json"];
SLRequest *postRequest = [SLRequest
requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:requestURL parameters:message];
UIImage *image = [self imageReduceSize:[UIScreen mainScreen].bounds.size:imgPost.image];
NSData *myData = UIImagePNGRepresentation(image);
[postRequest addMultipartData:myData withName:@"media" type:@"image/png" filename:@"TestImage"];
大家好。。很多天过去了,这个问题。没有人知道解决方案的线索吗?我只需要一个解决方法。你能给我这个@Stunner的twitter示例吗