Eth*_*len 1 iphone twitter cocoa-touch objective-c ios5
是否有可能在Twitter上使用iOS 5中的新Twitter API"关注"人们?
如果是这样,怎么样?我似乎无法弄清楚要走哪条路.
有人可以使用TWRequest请发布示例吗?谢谢.
添加Twitter和帐户框架,并使用以下方法:
- (IBAction)tweet_action
{
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];
NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
[tempDict setValue:@"numerologistiOS" forKey:@"screen_name"];
[tempDict setValue:@"true" forKey:@"follow"];
TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://api.twitter.com/1/friendships/create.json"]
parameters:tempDict
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);
if (urlResponse.statusCode == 200)
{
UIAlertView *statusOK = [[UIAlertView alloc]
initWithTitle:@"Thank you for Following!"
message:@"You are now following us on Twitter!"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
dispatch_async(dispatch_get_main_queue(), ^{
[statusOK show];
});
}
}];
}
}
}];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3499 次 |
| 最近记录: |