【问题标题】:Twitter.framework Image and message issueTwitter.framework 图片和消息问题
【发布时间】:2012-06-23 11:46:04
【问题描述】:

我正在使用 Twitter.framework 将带有消息的图像发布到 Twitter。但是我在我的 Twitter 帐户中看到没有消息的图像。我用这个代码

       // Create an account store object.
        ACAccountStore *accountStore = [[ACAccountStore alloc] init];

        // Create an account type that ensures Twitter accounts are retrieved.
        ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

        // Request access from the user to use their Twitter accounts.
        [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
            if(granted) {
                // Get the list of Twitter accounts.
                NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];


                if ([accountsArray count] > 0) {
                    // Grab the initial Twitter account to tweet from.
                    ACAccount *twitterAccount = [accountsArray objectAtIndex:0];



                    UIImage *image =[UIImage imageNamed:@"logo"];


                    TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update_with_media.json"] 
                                                                         parameters:[NSDictionary dictionaryWithObjectsAndKeys:@"Hello. This is a tweet.", @"status", @"My message", @"message", nil] requestMethod:TWRequestMethodPOST];

                    // "http://api.twitter.com/1/statuses/update.json" 

                    [postRequest addMultiPartData:UIImagePNGRepresentation(image) withName:@"media" type:@"multipart/png"];


                    // Set the account used to post the tweet.
                    [postRequest setAccount:twitterAccount];

                    [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                        NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]];
                        NSLog(@"output = %@\n\n", output);
                    }];
                }
            }
        }];

我在推特上看到的:

当我展开时:

但我没有看到消息

【问题讨论】:

    标签: iphone image ios5 twitter


    【解决方案1】:

    尝试以下代码,我正在使用它并且它工作正常。希望对你也有帮助

    -(IBAction)goTweet:(id)sender{
    
    if ([TWTweetComposeViewController canSendTweet])
    {
        TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc] init];
        [tweetSheet setInitialText:[NSString stringWithFormat:@"YOUR TWEET HERE"]];
    
        [tweetSheet addImage:[UIImage imageNamed:@"site-logo.jpg"]];
    
        [self presentModalViewController:tweetSheet animated:YES];
        [shareLoading stopAnimating];
    }
    else
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Twitter" 
                                                            message:@"Sorry, you can't send a Tweet yet, please make sure you are connected to the internet and have at least one Twitter account set up on your phone in Settings --> Twitter." 
                                                           delegate:self 
                                                  cancelButtonTitle:@"OK" 
                                                  otherButtonTitles:nil];
        [alertView show];
    
    }
    
    }
    

    【讨论】:

    • 谢谢,但如果有没有模态窗口的推文方法,我会更喜欢它。
    【解决方案2】:

    我发现,如何发送带有图像的文本: 添加此代码

    [postRequest addMultiPartData:[@"This photo is taken with my iPhone using nPassword!" dataUsingEncoding:NSUTF8StringEncoding] withName:@"status" type:@"multipart/form-data"];
    

    【讨论】:

      猜你喜欢
      • 2012-06-22
      • 1970-01-01
      • 1970-01-01
      • 2014-07-10
      • 2013-08-18
      • 2021-12-17
      • 1970-01-01
      • 1970-01-01
      • 2011-07-11
      相关资源
      最近更新 更多