繁体   English   中英

如何将Twitter中的私人推文发布到ios中的朋友/关注者?

[英]how can post private tweet in twitter to friend/followers in 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是朋友的Twitter ID

当我发布推文时,两个朋友得到如下错误

errors =     (
                {
            code = 189;
            message = "Error creating status.";
        }
    );

请提供有关如何在iOS中鸣叫特定朋友/关注者的帮助。

使用下面的链接我喜欢我的问题

NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/update_with_media.json"];

终于我找到了解决方案。 请尝试以下代码:

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]);
                               }];
        }
    }
}];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM