title: Twitter Streaming API - Objective-C
body: <p>I am working with <strong>the Twitter REST/Streaming APIs</strong>. When I want to access the REST API, I create a <code>NSMutableURLRequest</code> (that contains parameters such as access tokens and queries). I then use the request in conjunction with <code>NSURLSession</code> to load the data. I am using a library which creates the mutable request object for me (if I don't use the request object, then the Twitter API will not allow me to access the relevant user data).</p>
  
  <p>Now I am trying to load a Twitter timeline via the streaming API. One problem I am having is that I can't figure out how to use my custom mutable request object, with a <code>NSStream</code> object. The only thing I can do is to set the <code>host</code> URL link. But that is not good enough because I need to pass the user OAuth data (that is included in the mutable request object), in order for the Twitter API to allow me access to the user data.</p>
  
  <p>How can I attach a request object to the stream? Here is my code:</p>
  
  <pre><code>NSURL *website = [NSURL URLWithString:@"https://userstream.twitter.com/1.1/user.json"];
  
  CFReadStreamRef readStream;
  CFWriteStreamRef writeStream;
  CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)[website host], 80, &amp;readStream, &amp;writeStream);
  
  NSInputStream *inputStream = (__bridge_transfer NSInputStream *)readStream;
  NSOutputStream *outputStream = (__bridge_transfer NSOutputStream *)writeStream;
  [inputStream setDelegate:self];
  [outputStream setDelegate:self];
  [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
  [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
  [inputStream open];
  [outputStream open];
  </code></pre>