mercredi 31 décembre 2014

Error retrieving Twitter Timeline

I am using AFOAuth1Client in order to Authenticate and then retrieve the Home Timeline of a given Twitter User. However when I run my code I get this error:



Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 403" UserInfo=0x7fe160ca0070 {NSLocalizedRecoverySuggestion={"errors":[{"message":"Your credentials do not allow access to this resource","code":220}]}, NSErrorFailingURLKey=http://ift.tt/19WaRhi, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest: 0x7fe160ca88c0> { URL: http://ift.tt/19WaRhi }, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x7fe160dad9b0> { URL: http://ift.tt/19WaRhi } { status code: 403, headers {
"Content-Encoding" = deflate;
"Content-Length" = 94;
"Content-Type" = "application/json;charset=utf-8";
Date = "Wed, 31 Dec 2014 20:19:49 UTC";
Server = "tsa_b";
"Set-Cookie" = "guest_id=v1%3A142005718900451202; Domain=.twitter.com; Path=/; Expires=Fri, 30-Dec-2016 20:19:49 UTC";
"Strict-Transport-Security" = "max-age=631138519";
"x-connection-hash" = 2a42433adec68c7f4e4410d0df3e6713;
"x-response-time" = 5;
"x-spdy-version" = "3.1-NPN";
} }, NSLocalizedDescription=Expected status code in (200-299), got 403}


Here is how I am attempting to Authenticate:


SettingsViewController.m



- (void)authenticateWithTwitter {
self.twitterClient = [[AFOAuth1Client alloc] initWithBaseURL:[NSURL URLWithString:@"http://ift.tt/nSqRsl"]
key:@"XXXXXXXXXXXX"
secret:@"XXXXXXXXXXXX"];

[self.twitterClient authorizeUsingOAuthWithRequestTokenPath:@"oauth/request_token"
userAuthorizationPath:@"oauth/authorize"
callbackURL:[NSURL URLWithString:@"floadt://success"]
accessTokenPath:@"oauth/access_token"
accessMethod:@"GET"
scope:nil
success:^(AFOAuth1Token *accessToken, id response) {
[AFOAuth1Token storeCredential:accessToken withIdentifier:@"TwitterToken"];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"twitterActive"];
[[NSUserDefaults standardUserDefaults] synchronize];
} failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
}


StreamViewController.m



-(void)fetchTweets {
AFOAuth1Token *twitterToken = [AFOAuth1Token retrieveCredentialWithIdentifier:@"TwitterToken"];
[self.twitterClient setAccessToken:twitterToken];

self.twitterClient = [[AFOAuth1Client alloc] initWithBaseURL:[NSURL URLWithString:@"http://ift.tt/YFagLh"] key:@"XXXXXXXXX" secret:@"XXXXXXXXXX"];

[self.twitterClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
[self.twitterClient getPath:@"statuses/home_timeline.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSArray *responseArray = (NSArray *)responseObject;
NSLog(@"Response: %@", responseObject);
[responseArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
tweets = responseArray;
}];
[self.tableView reloadData];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}



Aucun commentaire:

Enregistrer un commentaire