我有一个问题,我有一些追随者,我想向所有追随者发送带有图像的直接消息,但我没有办法做到这一点。
我研究了整个文档,但找不到这样做的方法。
我的代码在这里:
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 上看到了所有其他类似的问题/答案,但我没有办法将带有图像的直接消息发送给关注者。
请不要将此问题视为重复问题并尝试解决我的问题。我会感激你的每一个线索。