Sto provando a lottare con questo problema per due giorni. Sto usando Fabric SDK e Rest kit, cercando di giocare con diversi servizi web di Rest API per Twitter. Posso accedere correttamente utilizzando TWTRLogInButton
con oggetto di sessione con authTokenSecret
, authToken
e altri valori. Quando cerco di ottenere cronologia utente, ho sempre arrivare risposta di errore in cambio come:Accesso alla cronologia utente di Twitter tramite Fabric SDK iOS
{"errors":[{"code":215,"message":"Bad Authentication data.
"}]}
completa log di errore è:
E restkit.network:RKObjectRequestOperation.m:297 Object request failed: Underlying HTTP request operation failed with error: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1011 "Expected status code in (200-299), got 400" UserInfo=0x1780f6f80 {NSLocalizedRecoverySuggestion={"errors":[{"code":215,"message":"Bad Authentication data."}]}, NSErrorFailingURLKey=https://api.twitter.com/1.1/statuses/user_timeline.json?user_id=3116882322&count=2&screen_name=ann_10p, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest: 0x178202740> { URL: https://api.twitter.com/1.1/statuses/user_timeline.json?user_id=3116882322&count=2&screen_name=ann_10p }, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x1702271e0> { URL: https://api.twitter.com/1.1/statuses/user_timeline.json?user_id=3116882322&count=2&screen_name=ann_10p } { status code: 400, headers {
"Content-Encoding" = gzip;
"Content-Length" = 87;
"Content-Type" = "application/json;charset=utf-8";
Date = "Wed, 01 Apr 2015 09:46:42 GMT";
Server = "tsa_a";
"Strict-Transport-Security" = "max-age=631138519";
"x-connection-hash" = 4c123a59a023cd86b2e9a3e9fc84cd7b;
"x-response-time" = 4;
} }, NSLocalizedDescription=Expected status code in (200-299), got 400}
2015-04-01 14:47:13.223 TwitterIntegration[1086:60b] I restkit.network:RKHTTPRequestOperation.m:154 GET 'https://api.twitter.com/1.1/statuses/user_timeline.json?user_id=3116882322&count=2&screen_name=ann_10p'
2015-04-01 14:47:13.225 TwitterIntegration[1086:60b] E restkit.network:RKHTTPRequestOperation.m:178 GET 'https://api.twitter.com/1.1/statuses/user_timeline.json?user_id=3116882322&count=2&screen_name=ann_10p' (400 Bad Request) [0.0013 s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1011 "Expected status code in (200-299), got 400" UserInfo=0x1780f6f80 {NSLocalizedRecoverySuggestion={"errors":[{"code":215,"message":"Bad Authentication data."}]}, NSErrorFailingURLKey=https://api.twitter.com/1.1/statuses/user_timeline.json?user_id=3116882322&count=2&screen_name=ann_10p, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest: 0x178202740> { URL: https://api.twitter.com/1.1/statuses/user_timeline.json?user_id=3116882322&count=2&screen_name=ann_10p }, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x1702271e0> { URL: https://api.twitter.com/1.1/statuses/user_timeline.json?user_id=3116882322&count=2&screen_name=ann_10p } { status code: 400, headers {
"Content-Encoding" = gzip;
"Content-Length" = 87;
"Content-Type" = "application/json;charset=utf-8";
Date = "Wed, 01 Apr 2015 09:46:42 GMT";
Server = "tsa_a";
"Strict-Transport-Security" = "max-age=631138519";
"x-connection-hash" = 4c123a59a023cd86b2e9a3e9fc84cd7b;
"x-response-time" = 4;
} }, NSLocalizedDescription=Expected status code in (200-299), got 400}
Codice:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self addLoginButton];
}
-(void) addLoginButton
{
TWTRLogInButton *logInButton = [TWTRLogInButton buttonWithLogInCompletion:^(TWTRSession *session, NSError *error) {
// play with Twitter session
if(session)
{
NSLog(@"logged in success! with session : %@", session);
[Global sharedInstance].session = session;
[self requestUserTimeline];
}
else
{
NSLog(@"session is null");
}
}];
logInButton.center = self.view.center;
[self.view addSubview:logInButton];
}
-(void) requestUserTimeline
{
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[UserTimeline class]];
[mapping addAttributeMappingsFromDictionary:@{
@"text": @"tweetText",
@"favorited": @"favourited",
@"created_at": @"createdAt",
@"user.name": @"name",
@"id": @"tweetID",
@"user.profile_image_url": @"profileImageURL"
}];
NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful); // Anything in 2xx
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping pathPattern:nil keyPath:nil statusCodes:statusCodes];
NSString *params = [NSString stringWithFormat:@"?user_id=3116882322&count=2&screen_name=ann_10p",[Global sharedInstance].session.userID,[Global sharedInstance].session.userName];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[@"https://api.twitter.com/1.1/statuses/user_timeline.json" stringByAppendingString:params]]];
[request setHTTPMethod:@"GET"];
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[responseDescriptor]];
[operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
UserTimeline *timeline = [result firstObject];
NSLog(@"Mapped the article: %@", timeline);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"Failed with error: %@", [error localizedDescription]);
}];
[operation start];
}
Per favore aiutatemi nel debug di questo problema Grazie
Dove stai usando il token di autenticazione? – Wain
Come posso usarlo @Wain? Non c'è alcuna documentazione sul passaggio del token di autenticazione in alcuna richiesta. Ma sto ricevendo uno dopo il login. – NightFury
Ci deve essere, perché hai un token e un errore di autenticazione. Anche i token di autenticazione sono standard. Non ho guardato i documenti ma è lì che devi cercare una guida. – Wain