我对POST到twitter的概念不熟悉。我看了here以了解如何从Twitter获取内容。但我找不到任何关于如何将内容发布到Twitter的示例。
如何告诉Twitter userXYZ发布推文?如何推文本身的文本正文。
同样,我对这个概念很陌生。
答案 0 :(得分:1)
您可以在API文档中轻松找到它们。我认为你是looking for this。
此外,还有一些问题已在SO中提出。您还可以check this。
答案 1 :(得分:0)
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];
}
答案 2 :(得分:0)
谢谢拉沙德。这就是我现在使用的。有用。
- (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);
}
}];
}
}
}];
}