簡體   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