iOS应用程序 Twitter开发代码
iOS应用程序 Twitter开发代码是本文要介绍的内容,先来了解一下Twitter,它是国外的一个社交网络及微博客服务的网站。它利用无线网络,有线网络,通信技术,进行即时通讯,是微博客的典型应用。
Twitter允许用户将自己的最新动态和想法以短信形式发送给手机和个性化网站群,而不仅仅是发送给个人。2006年,博客技术先驱blogger.com创始人埃文·威廉姆斯(Evan Williams)创建的新兴公司Obvious推出了大围脖服务。在最初阶段,这项服务只是用于向好友的手机发送文本信息。2006年底,Obvious对服务进行了升级,用户无需输入自己的手机号码,而可以通过即时信息服务和个性化Twitter网站接收和发送信息。
Twitter 现在欧美地区极其火爆,如果各位开发者想在应用中增加 Twitter 功能,可以看一下许靖昕先生在博客中分享的代码。
代码地址:http://blog.csdn.net/cloudhsu/article/details/6048626
- (void) postToTwitter
{
// Since this will be launched in a separate thread, we need
// an autorelease pool
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:
[NSURL URLWithString:@"http://TWITTER_ACCOUNT:[email protected]/statuses/update.xml"]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
// The text to post
NSString *msg = @"testing";
// Set the HTTP request method
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[[NSString stringWithFormat:@"status=%@", msg]
dataUsingEncoding:NSASCIIStringEncoding]];
NSURLResponse *response;
NSError *error;
if ([NSURLConnection sendSynchronousRequest:request
returningResponse:&response error:&error] != nil)
NSLog(@"Posted to Twitter successfully.");
else
NSLog(@"Error posting to Twitter.");
// Release pool
[pool release];
}
[NSThread detachNewThreadSelector:@selector(postToTwitter)
toTarget:self withObject:nil];
- (void) postToTwitter
{
// Since this will be launched in a separate thread, we need
// an autorelease pool
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:
[NSURL URLWithString:@"http://TWITTER_ACCOUNT:[email protected]/statuses/update.xml"]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
// The text to post
NSString *msg = @"testing";
// Set the HTTP request method
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[[NSString stringWithFormat:@"status=%@", msg]
dataUsingEncoding:NSASCIIStringEncoding]];
NSURLResponse *response;
NSError *error;
if ([NSURLConnection sendSynchronousRequest:request
returningResponse:&response error:&error] != nil)
NSLog(@"Posted to Twitter successfully.");
else
NSLog(@"Error posting to Twitter.");
// Release pool
[pool release];
} [NSThread detachNewThreadSelector:@selector(postToTwitter) toTarget:self withObject:nil];
相关推荐
好好学习天天 2020-07-21
heqiang0 2020-06-25
定格 2020-05-30
定格 2020-04-17
zhoutaifeng 2020-04-17
zhoutaifeng 2020-04-17
zhoutaifeng 2020-03-07
好好学习天天 2020-03-06
heqiang0 2020-03-02
知更鸟CoolLee 2020-02-27
发条戏子 2020-02-22
herogood 2020-02-19
好好学习天天 2020-02-17
heqiang0 2020-02-13
heqiang0 2019-12-12