如何分享内容到Twitter。

iOS 码拜 9年前 (2015-05-09) 1964次浏览 0个评论
 

如题。

40分
- (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:PASSWORD@twitter.com/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]; 
}   
谢谢。。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明如何分享内容到Twitter。
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!