3

我的应用程序有来自 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.}
4

0 回答 0