Skip to content

Commit

Permalink
Fake out HTTP client User Agent to allow Twitter public timeline requ…
Browse files Browse the repository at this point in the history
…ets to succeed. fixes RestKit#1308
  • Loading branch information
blakewatters committed May 15, 2013
1 parent 4b2c10e commit 3313fed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Examples/RKTwitter/Classes/RKTwitterAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
// Initialize HTTPClient
NSURL *baseURL = [NSURL URLWithString:@"https://twitter.com"];
AFHTTPClient* client = [[AFHTTPClient alloc] initWithBaseURL:baseURL];

// HACK: Set User-Agent to Mac OS X so that Twitter will let us access the Timeline
[client setDefaultHeader:@"User-Agent" value:[NSString stringWithFormat:@"%@/%@ (Mac OS X %@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleIdentifierKey], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey], [[NSProcessInfo processInfo] operatingSystemVersionString]]];

//we want to work with JSON-Data
[client setDefaultHeader:@"Accept" value:RKMIMETypeJSON];

Expand Down
3 changes: 3 additions & 0 deletions Examples/RKTwitterCoreData/Classes/RKTwitterAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
// Initialize RestKit
NSURL *baseURL = [NSURL URLWithString:@"https://twitter.com"];
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:baseURL];

// HACK: Set User-Agent to Mac OS X so that Twitter will let us access the Timeline
[objectManager.HTTPClient setDefaultHeader:@"User-Agent" value:[NSString stringWithFormat:@"%@/%@ (Mac OS X %@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleIdentifierKey], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey], [[NSProcessInfo processInfo] operatingSystemVersionString]]];

// Enable Activity Indicator Spinner
[AFNetworkActivityIndicatorManager sharedManager].enabled = YES;
Expand Down

0 comments on commit 3313fed

Please sign in to comment.