am looking to use the Twitter Streaming API in iOS5 by using TWReqeust. The request is a a POST request. This is the code I am using:
-
ACAccountStore *store = [[ACAccountStore alloc] init];
-
ACAccountType *twitterAccountType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
-
-
[store requestAccessToAccountsWithType:twitterAccountType withCompletionHandler:^(BOOL granted, NSError *error)
-
{ -
if (!granted){
-
NSLog(@"User rejected access to his account.");
-
} else {
-
//Grab the available accounts -
NSArray *twitterAccounts = [store accountsWithAccountType:twitterAccountType];
-
-
if([twitterAccounts count] > 0)
-
{ -
//Use the first account for simplicity -
ACAccount *account = [twitterAccounts objectAtIndex:0];
-
-
//Authenticated request -
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
-
[params setObject:@"1" forKey:@"include_entities"];
-
-
//Endpoint to call -
NSURL *url = [NSURL URLWithString:@"https://stream.twitter.com/1/statuses/filter.json?track=winning"];
-
-
TWRequest *request = [[TWRequest alloc] initWithURL:url parameters:params requestMethod:TWRequestMethodPOST];
-
-
//Attach account object to request -
[request setAccount:account];
-
-
NSURLRequest *twitterRequest = [request signedURLRequest];
-
-
NSURLConnection *twitterConnection = [[NSURLConnection alloc] initWithRequest:twitterRequest delegate:self startImmediately:NO];
-
-
[twitterConnection scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
-
[twitterConnection start];
-
-
if (twitterConnection)
-
{ -
NSLog(@"Connection!!");
-
} else {
-
NSLog(@"NO Connection!!");
-
} -
} -
} -
}];
I am getting a response and a data object. However when I convert the data object into a string I get this response:
-
Data that is received: <html>
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
-
<title>Error 401 Unauthorized</title>
-
</head>
-
<body>
-
<h2>HTTP ERROR: 401</h2>
-
<p>Problem accessing '/1/statuses/filter.json?track=winning'. Reason:
-
<pre> Unauthorized</pre>
-
</body>
-
</html>
I am not sure why the request is unauthorized since I am using the account from the account store. Any idea what I am doing wrong?
