因为要用到,所以找来,和大家分享:
1. 首先在http://open.t.sina.com.cn/中申请成为开发者,再创建不同的应用,获得相应的App Key (在下面链接中的source即为app key)
2. 登录认证:
NSString *authString = [NSString stringWithFormat:@"%@:%@",sinaIDField.text,sinaPasswordField.text];
NSData *authData = [authString dataUsingEncoding:NSUTF8StringEncoding];
NSString *authValue = [NSString stringWithFormat:@"Basic %@",[authData base64EncodingWithLineLength:80]];
NSURL *url = [NSURL URLWithString:@"http://api.t.sina.com.cn/account/verify_credentials.xml?source=3930264715"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setHTTPMethod:@"GET"];
[request setValue:authValue forHTTPHeaderField:@"Authorization"];
NSURLResponse *response;
NSError *error;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
[request release];
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
int statusCode = [httpResponse statusCode];
NSLog(@"status code = %d",statusCode);
if (statusCode != 200) {
alertTitle = @"帐号或密码错误";
alertMassage = @"请您输入正确的帐号和密码!";
}else {
alertTitle = @"";
alertMassage = @"登录成功!";
}
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:alertTitle
message:alertMassage
delegate:nil can