我的应用程序有来自Twitter的令牌,并希望与他们一起制作SLRequest但是当我这样做而没有保存ACAccount时却没有。我该如何解决这个问题?
代码:
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountCredential *credential = [[ACAccountCredential alloc] initWithOAuthToken:@"token" tokenSecret:@"secret"];
ACAccountType *twitterAcctType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
ACAccount *newAccount = [[ACAccount alloc] initWithAccountType:twitterAcctType];
newAccount.credential = credential;
newAccount.username = @"username";
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:[NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/user_timeline.json"] parameters:@{ @"screen_name" : @"username" }];
request.account = newAccount;
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSLog(@"ResponseData: %@", [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding]);
NSLog(@"StatusCode: %d", urlResponse.statusCode);
NSLog(@"Error: %@", error);
}];
日志:
2013-06-20 00:07:55.554 MyApp[6009:c07] ResponseData:
2013-06-20 00:07:55.555 MyApp[6009:c07] StatusCode: 0
2013-06-20 00:07:55.555 MyApp[6009:c07] Error: Error Domain=SLErrorDomain Code=0 "Could not prepare the URL request." UserInfo=0x9499020 {NSLocalizedDescription=Could not prepare the URL request.}