我尝试使用以下代码为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中的特定朋友/粉丝发送推文..
答案 0 :(得分:0)
使用以下链接我解决了我的问题
NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/update_with_media.json"];
答案 1 :(得分:0)
最后我得到了一个解决方案。请尝试以下代码:
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/direct_messages/new.json"];
ACAccount *twitterAccount = [accountsList lastObject];
NSDictionary *param =@{@"user_id":[NSString stringWithFormat:@"%@",userid],@"text":@"post successfully....."};
SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:url parameters:param];
[postRequest setAccount:twitterAccount];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResposnse, NSError *error){
NSError *jsonError = nil;
NSLog(@"response value is: %@ %d ",friendsdata,[urlResposnse statusCode]);
}];
}
}
}];