通过iOS 5 twitter API发送任何推文收藏 [英] Making any tweet favourite through iOS 5 twitter API
问题描述
我正在制作推特客户端应用。客户端的要求之一也是将特定推文标记为应用程序中的最爱。我正在搜索这两天,但没有任何线索..任何人都可以指导我,如果有可能通过ios 5的Twitter API这样做就可以了。如果是,那么如何?
I am working on making a twitter client app. One of the requirement of client is also to mark the specifice tweets as favourite from the app. I am searching on this for two days but no clue.. Can any one plz guide me if it is possible to do so through ios 5's twitter API on not. If yes then how??
推荐答案
是的,可以使用Twitter和账户框架:
Yes thats possible using Twitter and Accounts framework:
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted) {
// Get the list of Twitter accounts.
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
// For the sake of brevity, we'll assume there is only one Twitter account present.
// You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present.
if ([accountsArray count] > 0) {
// Grab the initial Twitter account to tweet from.
ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
NSString* urlString = [NSString stringWithFormat:@"http://api.twitter.com/1/favorites/create/%d.json", tweetID];
TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:urlString]
parameters:nil
requestMethod:TWRequestMethodPOST];
[postRequest setAccount:twitterAccount];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]];
NSLog(@"%@", output);
}];
}
}
}];
}
另请查看Twitter REST API文档: https://dev.twitter.com/docs/api/1/post/favorites / create /%3Aid
Also take a look at the Twitter REST API documentation: https://dev.twitter.com/docs/api/1/post/favorites/create/%3Aid
这篇关于通过iOS 5 twitter API发送任何推文收藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!