【发布时间】:2014-07-21 13:16:53
【问题描述】:
我对 POST 到 twitter 的概念不熟悉。我查看了here,以了解如何从 twitter 获取内容。但我找不到任何关于如何在 Twitter 上发布内容的示例。
我如何告诉 twitter userXYZ 正在发布一条推文?推文本身的正文怎么样。
再说一次,我对这个概念很陌生。
【问题讨论】:
我对 POST 到 twitter 的概念不熟悉。我查看了here,以了解如何从 twitter 获取内容。但我找不到任何关于如何在 Twitter 上发布内容的示例。
我如何告诉 twitter userXYZ 正在发布一条推文?推文本身的正文怎么样。
再说一次,我对这个概念很陌生。
【问题讨论】:
您可以在 API 文档中轻松找到这些内容。我想你是looking for this。
SO 中已经提出了一些问题。你也可以check this。
【讨论】:
Using Twitter SDK import #import<Twitter/Twitter.h> in your .h or .m file
if ([TWTweetComposeViewController canSendTweet])
{
NSURL* aURL = [NSURL URLWithString:@"your image Url"];
NSData* data = [[NSData alloc] initWithContentsOfURL:aURL];
UIImage *img1 = [UIImage imageWithData:data];
// Initialize Tweet Compose View Controller
TWTweetComposeViewController *vc = [[TWTweetComposeViewController alloc] init];
// Settin The Initial Text
[vc setInitialText:@"Setting The Initial Text"];
[vc addImage:img1];
// Adding a URL
strWEBTwitter = @"Pass Your URL here"
[vc addURL:[NSURL URLWithString:strWEBTwitter]];
// Setting a Completing Handler
[vc setCompletionHandler:^(TWTweetComposeViewControllerResult result)
{
[self dismissViewControllerAnimated:YES completion:nil];
NSLog(@"Result : %d", result);
if (result == TWTweetComposeViewControllerResultDone)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Message" message:@"Thanks for sharing." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show];
}
else if (result == TWTweetComposeViewControllerResultCancelled)
{
NSLog(@"Cancle")
}
}];
// Display Tweet Compose View Controller Modally
[self presentViewController:vc animated:YES completion:nil];
} else
{
// Show Alert View When The Application Cannot Send Tweets
NSString *message = @"There are no Twitter accounts configured. You can add or create a Twitter account in Settings.";
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"No Twitter Accounts" message:message delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Cancel",nil];
[alertView show];
}
【讨论】:
谢谢拉沙德。这就是我现在正在使用的。有用。
- (void)testPost {
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error)
{
if (granted)
{
NSArray *accounts = [accountStore accountsWithAccountType:accountType];
if (accounts.count)
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:@"check Check CHECK" forKey:@"status"];
NSString *retweetString = [NSString stringWithFormat:@"https://api.twitter.com/1.1/statuses/update.json"];
NSURL *retweetURL = [NSURL URLWithString:retweetString];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:retweetURL parameters:dict];
request.account = [accounts objectAtIndex:0];
[request performRequestWithHandler:^(NSData *responseData1, NSHTTPURLResponse *urlResponse, NSError *error)
{
if (responseData1)
{
NSError *error1 = nil;
id response = [NSJSONSerialization JSONObjectWithData:responseData1 options:NSJSONReadingMutableLeaves error:&error1];
NSLog(@"%@", response);
}
}];
}
}
}];
}
【讨论】: