【问题标题】:how can post private tweet in twitter to friend/followers in ios?如何将 Twitter 中的私人推文发布给 ios 中的朋友/关注者?
【发布时间】: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.formathttps://api.twitter.com/1.1/direct_messages/new.json

标签: ios iphone twitter


【解决方案1】:

使用下面的链接我解决了我的问题

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

【讨论】:

    【解决方案2】:

    终于找到了解决办法。请尝试我的以下代码:

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

    【讨论】:

      猜你喜欢
      • 2014-08-14
      • 2011-02-04
      • 1970-01-01
      • 2012-05-22
      • 1970-01-01
      • 2021-08-04
      • 2011-11-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多