gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 09:20:27 25 4
gpt4 key购买 nike

我可以像苹果示例一样使用 TWRequest 轻松发送推文,

 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 或其他服务。或者还有其他方法可以将图像与推文一起发送吗?

谢谢

最佳答案

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

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

关于twitter - 在 IOS5 中使用 TWrequest 将带有文本的图像发送到 Twitter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8034764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com