gpt4 book ai didi

objective-c - 如何在 ios5 中从我的 iPhone 发送图像到推特上

转载 作者:搜寻专家 更新时间:2023-10-30 20:01:00 25 4
gpt4 key购买 nike

我想使用 twitter api twitter+OAuth 从我的 iphone 在 twitter 上分享图片,但我不知道如何从我的 iphone 分享它。我曾尝试使用 sharekit 进行相同的操作,但没有成功。你能告诉我如何使用 twitter api 从 iphone 在 twitter 上分享图片吗?

最佳答案

zot 提供的链接有效,但我必须添加一些代码,而且我必须添加两个框架 Twitter.framework 和 Account.framework。修改后的代码如下

- (IBAction)sendCustomTweet:(id)sender {
// Create an account store object.
ACAccountStore *accountStore = [[ACAccountStore alloc] init];

// Create an account type that ensures Twitter accounts are retrieved.
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

// Request access from the user to use their Twitter accounts.
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted) {
// Get the list of Twitter accounts.
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];


if ([accountsArray count] > 0) {
// Grab the initial Twitter account to tweet from.
ACAccount *twitterAccount = [accountsArray objectAtIndex:0];


UIImage *image =[UIImage imageNamed:@"Icon.png"];


TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update_with_media.json"]
parameters:[NSDictionary dictionaryWithObject:@"Hello. This is a tweet." forKey:@"status"] requestMethod:TWRequestMethodPOST];

// "http://api.twitter.com/1/statuses/update.json"

[postRequest addMultiPartData:UIImagePNGRepresentation(image) withName:@"media" type:@"multipart/png"];


// Set the account used to post the tweet.
[postRequest setAccount:twitterAccount];

[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]];
[self performSelectorOnMainThread:@selector(displayText:) withObject:output waitUntilDone:NO];
}];
}
}
}];
}

关于objective-c - 如何在 ios5 中从我的 iPhone 发送图像到推特上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8336739/

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