我使用Fabric,用于登录Twitter,现在我需要发送没有作曲家视图的推文,我使用了这段代码:
[[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error) {
TWTRAPIClient *client = [[TWTRAPIClient alloc] initWithUserID:session.userID];
NSString *url = @"https://api.twitter.com/1.1/statuses/update.json";
NSMutableDictionary *message = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Test Text",@"status", nil];
NSURLRequest *preparedRequest = [client URLRequestWithMethod:@"POST" URL:url parameters:message error:&error];
[client sendTwitterRequest:preparedRequest completion:^(NSURLResponse *urlResponse, NSData *responseData, NSError *error){
if(!error){
NSError *jsonError;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&jsonError];
NSLog(@"%@", json);
}else{
NSLog(@"Error: %@", error);
}
}];
}];
但总是回复错误:
错误:错误域= TWTRNetworkingErrorDomain代码= -1011“请求失败:未授权(401)”UserInfo = {NSLocalizedFailureReason =,TWTRNetworkingStatusCode = 401,NSErrorFailingURLKey = https://api.twitter.com/1.1/statuses/update.json,NSLocalizedDescription =请求失败:未授权(401)}
会话是正确的,但我无法理解如何为请求设置令牌