问题描述
我可以像苹果示例一样使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!