在IOS5中使用TWrequest将带有文本的图像发送到Twitter

在IOS5中使用TWrequest将带有文本的图像发送到Twitter,twitter,ios5,Twitter,Ios5,我可以使用TWRequest轻松发送tweet,就像苹果的例子一样 ACAccountStore *account = [[ACAccountStore alloc] init]; ACAccountType *accountType = [accountaccountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; // Request access from the user to access their T

我可以使用TWRequest轻松发送tweet,就像苹果的例子一样

 ACAccountStore *account = [[ACAccountStore alloc] init];
 ACAccountType *accountType = [accountaccountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

// Request access from the user to access their Twitter account
[account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) 
 {
     // Did user allow us access?
     if (granted == YES)
     {
         // Populate array with all available Twitter accounts
         NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];

         // Sanity check
         if ([arrayOfAccounts count] > 0) 
         {
             // Keep it simple, use the first account available
             ACAccount *acct = [arrayOfAccounts objectAtIndex:0];

             // Build a twitter request
           TWRequest *postRequest = [[TWRequest alloc] initWithURL:
                                  [NSURL URLWithString:@"http://api.twitter.com/1/statuses/update.json"] 
                                                          parameters:[NSDictionary dictionaryWithObject:@"tweet goes here" 
                                                                                                 forKey:@"status"] requestMethod:TWRequestMethodPOST];             

             // Post the request
             [postRequest setAccount:acct];

            // Block handler to manage the response
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) 
              {
                  NSLog(@"Twitter response, HTTP response: %i", [urlResponse statusCode]);
              }];
但我想知道是否有可能用某种方式通过tweet发送图像,而不是通过twitpic或其他服务。或者有没有其他方法可以在推文中同时发送图像

谢谢,这是可能的。 您需要使用addMultiPartData:withName:type:method为您的tweet添加属性。 状态文本将不会显示,直到您将其添加为多部分数据

TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update_with_media.json"] parameters:nil requestMethod:TWRequestMethodPOST];
NSData *myData = UIImagePNGRepresentation(img);
[postRequest addMultiPartData:myData withName:@"media" type:@"image/png"];
myData = [[NSString stringWithFormat:@"Any status text"] dataUsingEncoding:NSUTF8StringEncoding];
[postRequest addMultiPartData:myData withName:@"status" type:@"text/plain"];

那么最后的代码是什么样的?@Andrey我只想发送文本,而不是TWRequest URL。@Coder您不需要在媒体上使用update\u。Apple示例使用以下参数:TWRequest*postRequest=[[TWRequest alloc]initWithURL:[NSURL URLWithString:@”参数:[NSDictionary Dictionary dictionaryWithObject:@“您好。这是一条推文。”forKey:@“status”]requestMethod:TWRequestMethodPOST];