在 IOS5 中使用 TWrequest 将带有文本的图像发送到 Twitter [英] Use TWrequest to send an image with a text to Twitter in IOS5

查看:20
本文介绍了在 IOS5 中使用 TWrequest 将带有文本的图像发送到 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]);
              }];

但我想知道是否可以使用 http://api.twitter.com/1/statuses/update_with_media.json 以某种方式发送带有推文的图像,而不是通过 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"];

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆