Note that there are some explanatory texts on larger screens.

plurals
  1. POTwitter iOS Streaming API: no data being received
    primarykey
    data
    text
    <p>I'm trying to modify Apple's sample code for using the Twitter API so that I can use the streaming API to filter tweets. I am attempting to implement the method suggested in response to this question:</p> <p><a href="https://stackoverflow.com/questions/8566742/does-twrequest-work-for-the-twitter-streaming-api">Does TWRequest work for the twitter streaming api?</a></p> <p>I have created the signed NSURLRequest and NSURLConnection objects as suggested, and set the delegate for the connection object. A valid twitter account is selected and used to sign the url. The problem is that the delegates connection:didReceiveData: method is never being called.</p> <p>Here's my code:</p> <pre><code>@implementation Twitter -(id)init{ if (self=[super init]) { NSLog(@"Twitter init"); // Tell the notification centre to inform the app if the twitter account changes [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(twitterAccountChanged) name:ACAccountStoreDidChangeNotification object:nil]; // Create an account store object. ACAccountStore *accountStore = [[ACAccountStore alloc] init]; // Create an account type that ensures Twitter accounts are retrieved. ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; // Request access from the user to use their Twitter accounts. [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) { if(granted) { NSLog(@"Twitter: Access to twitter accounts granted"); // Get the list of Twitter accounts. NSArray *accountsArray = [accountStore accountsWithAccountType:accountType]; // Pick the twitter account to use if ([accountsArray count] &gt; 0) { // Grab the initial Twitter account to tweet from. ACAccount *twitterAccount = [accountsArray objectAtIndex:0]; // This is for a status filter NSURL *url=[NSURL URLWithString:@"https://stream.twitter.com/1/statuses/filter.json"]; // Create the parameters dictionary NSDictionary *dictionary=[NSDictionary dictionaryWithObjectsAndKeys:@"twitter", @"track", nil]; // Create TWRequest object TWRequest *req=[[TWRequest alloc] initWithURL:url parameters:dictionary requestMethod:TWRequestMethodPOST]; // Set the account [req setAccount:twitterAccount]; // Get a signed URL request NSURLRequest *signedRequest=[req signedURLRequest]; // Initate the connection [NSURLConnection connectionWithRequest:signedRequest delegate:self]; } else { NSLog(@"Twitter: No twitter accounts to access"); } } else { NSLog(@"Twitter: Access to twitter accounts denied"); } }]; return self; } return nil; } -(void)twitterAccountChanged{ NSLog(@"Twitter twitterAccountChanged"); } -(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ NSLog(@"data received"); } </code></pre> <p>The output from the program is:</p> <pre><code>2012-07-24 09:50:03.668 TwitterAPITest[36722:10403] Twitter init 2012-07-24 09:50:03.836 TwitterAPITest[36722:11d03] Twitter: Access to twitter accounts granted </code></pre> <p>As you can see, everything appears to work OK, the only problem is that the delegate method is never called and I currently have no idea why.</p> <p>Any help would be much appreciated...</p> <p>Mike</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload