【发布时间】:2014-03-03 05:58:20
【问题描述】:
我尝试使用以下 ios 代码向朋友发布消息
-(void)postMessageToFriend:(NSString *)ID withImage:(UIImage *)image{
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
if (granted && !error) {
NSArray *accountsList = [accountStore accountsWithAccountType:accountType];
int NoOfAccounts = [accountsList count];
if (NoOfAccounts >0) {
NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/show.json"];
ACAccount *twitterAccount = [accountsList lastObject];
NSDictionary *p =@{@"status":@"post successfully.....",@"user_id":ID};
SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:url parameters:p];
NSData *imageData = UIImageJPEGRepresentation(image,0.5);
[postRequest addMultipartData:imageData withName:@"media[]" type:@"image/jpeg" filename:@"image.jpg"];
[postRequest setAccount:twitterAccount];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResposnse, NSError *error){
NSError *jsonError = nil;
NSDictionary *friendsdata = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONWritingPrettyPrinted error:&jsonError];
NSLog(@"response value is: %@ %d ",friendsdata,[urlResposnse statusCode]);
}];
}
}
}];
}
这里的ID是朋友的推特ID
当我发布推文时,两个朋友收到如下错误
errors = (
{
code = 189;
message = "Error creating status.";
}
);
请帮助如何在 ios 中向特定的朋友/关注者发推文。
【问题讨论】:
-
试试这个网址
https://api.twitter.com/1.1/direct_messages/new.format或https://api.twitter.com/1.1/direct_messages/new.json