xcode 在没有 TWTweetComposeViewController 的情况下发送推文
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14192003/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sending Tweet without TWTweetComposeViewController
提问by coctile
I want to send a tweet directly from my iPhone app without showing TWTweetComposeViewController
pop up
我想直接从我的 iPhone 应用程序发送推文而不显示TWTweetComposeViewController
弹出窗口
Also i want to get all followers is there a way to do it from twitter framework on the ios5 or should i use another api!
另外我想让所有的追随者有办法从 ios5 上的 twitter 框架做到这一点,或者我应该使用另一个 api!
If I have to use another api can u specify a great api for me ? because all the apis i found on the internet was so old.
如果我必须使用另一个 api,你可以为我指定一个很棒的 api 吗?因为我在互联网上找到的所有 api 都太旧了。
Thanks in advance
提前致谢
回答by AndrejKolar
You can use TWRequest
for programatically posting tweets from my app, if you are using iOS 5.0 and up. Posting tweets is quite straightforward and there is no need for an external framework or anything.
TWRequest
如果您使用的是 iOS 5.0 及更高版本,您可以使用我的应用程序以编程方式发布推文。发布推文非常简单,不需要外部框架或任何东西。
You need the #import <Twitter/Twitter.h>
. You retrieve the twitter account from the iPhone account store (you could check if there are multiple accounts) and then you use the account to post the request.
你需要#import <Twitter/Twitter.h>
. 您从 iPhone 帐户商店检索 twitter 帐户(您可以检查是否有多个帐户),然后使用该帐户发布请求。
Here is an example of a method for posting a tweet with an image.
这是发布带有图像的推文的方法示例。
- (void)shareTwitterImage:(UIImage *)image
{
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
{
if(granted)
{
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
if ([accountsArray count] > 0)
{
ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update_with_media.json"] parameters:[NSDictionary dictionaryWithObject:self.textViewOutlet.text forKey:@"status"] requestMethod:TWRequestMethodPOST];
[postRequest addMultiPartData:UIImagePNGRepresentation(image) withName:@"media" type:@"multipart/png"];
[postRequest setAccount:twitterAccount];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
//show status after done
NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]];
NSLog(@"Twiter post status : %@", output);
}];
}
}
}];
}
回答by MCKapur
There are quite a few options:
有很多选择:
Well, on iOS 6, there is the Apple Social
framework, and you can use SLComposeViewController
to post to Twitter as well as Facebook and Sina Weibo, here are the docs. TWTweetComposeViewController
has been deprecated, devices running iOS 6 will have to run into backward compatibility -- so avoid that.
好吧,在 iOS 6 上,有 AppleSocial
框架,你可以SLComposeViewController
用来发布到 Twitter 以及 Facebook 和新浪微博,这里是文档。TWTweetComposeViewController
已被弃用,运行 iOS 6 的设备将不得不向后兼容——所以要避免这种情况。
There is also ShareKit, however I do not generally recommend it, its messy and bloated. Lastly there is the Oauth Library in iOS... create a consumer key and secret key. You can also call the Twitter API with TWRequest.
还有ShareKit,但我一般不推荐它,它凌乱而臃肿。最后是iOS 中的Oauth 库……创建消费者密钥和秘密密钥。您还可以使用 TWRequest 调用 Twitter API。
That's all of them I can think of.
我能想到的就这些。
Rohan.
罗汉。
回答by Vijay Tholpadi
In case you plan on integrating TwitterKit by Twitter to perform the tweets via your custom twitter app then this might help you.
如果您计划通过 Twitter 集成 TwitterKit 以通过您的自定义 Twitter 应用程序执行推文,那么这可能对您有所帮助。
https://stackoverflow.com/a/28602749/1740354
https://stackoverflow.com/a/28602749/1740354
With the same methods you can get the followers list by using the following API https://dev.twitter.com/rest/reference/get/followers/list
使用相同的方法,您可以使用以下 API https://dev.twitter.com/rest/reference/get/followers/list获取关注者列表
Hope it helps.
希望能帮助到你。