本文介绍了使用TWrequest在IOS5中将带有文本的图像发送到Twitter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以根据苹果示例使用TWRequest轻松发送推文,

I am able to send a tweet easily using TWRequest like this as per the apple example,

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

但我想知道是否可以使用以某种方式发送带有推文的图片,而不是通过twitpic或另一项服务。或者是否有其他方式发送图像和推文?

but i was wondering if it is possible to use http://api.twitter.com/1/statuses/update_with_media.json in some way to send an image with the tweet instead of going via twitpic or another service. Or is there another way to send an image along with the tweet?

谢谢

推荐答案

有可能。
您需要使用addMultiPartData:withName:type:方法为您的推文添加属性。
状态文本在将其添加为多部分数据之前不会显示。

It is possible.You'll need to use addMultiPartData:withName:type: method for adding attributes for your tweet.Status text won't be displayed until you add it as multipart data.

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"];

这篇关于使用TWrequest在IOS5中将带有文本的图像发送到Twitter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 09:16