업데이트 :iPhone Twitter 통합 : 로그인 확인
다음을 사용하면 XML 응답이 반환됩니다. NSXMLParser를 사용하여 "오류"요소를 확인합니다. 가장 깨끗한 방법은 아니지만 작업을 완료합니다. 나는 제안을 위해 열려 있습니다.
NSURLResponse *response;
NSError *error;
NSData* result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *resultString = [[NSString alloc] initWithData:result encoding:NSASCIIStringEncoding];
NSLog(@"myResult: %@", resultString);
원래의 게시물 :
다음 코드 게시물은 트위터 :
NSString *compoundLoginString = [NSString stringWithFormat:@"http://%@:%@@twitter.com/statuses/update.xml",extractedUsername, extractedPassword];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:
[NSURL URLWithString:compoundLoginString]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];
// The text to post
NSString *msg = tweetText;
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[[NSString stringWithFormat:@"status=%@", msg]
dataUsingEncoding:NSASCIIStringEncoding]];
NSURLResponse *response;
NSError *error;
if ([NSURLConnection sendSynchronousRequest:request
returningResponse:&response error:&error] != nil){
[self postSuccessfulAlert];
}else{
[self postNotSuccessfulAlert];
}
내가 위의 조각에 진행하기 전에 사용자 이름과 암호가 정확한지 확인할 수 있습니다 방법에 대한 궁금 코드
튜토리얼에서 다음 코드를 발견했지만이 기능을 구현하거나 호출하는 방법이 확실하지 않습니다.
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
if ([challenge previousFailureCount] == 0) {
NSURLCredential *newCredential;
newCredential=[NSURLCredential credentialWithUser:[self username]
password:[self password]
persistence:NSURLCredentialPersistenceNone];
[[challenge sender] useCredential:newCredential
forAuthenticationChallenge:challenge];
} else {
[[challenge sender] cancelAuthenticationChallenge:challenge];
// inform the user that the user name and password
// in the preferences are incorrect
NSLog(@"Invalid Username or Password");
}
}
아이디어가 있으십니까?
다음 튜토리얼 모두에서 코드 스 니펫을 작성했습니다. 사용자 이름과 로그인이 http://twitter.com/account/verify_credentials.xml 또는 http://api.twitter.com/1/account/verify_credentials.xml에 인증 요청을함으로써 올바른 경우
http://iosdevelopertips.com/networking/post-to-a-twitter-account-from-the-iphone.html
및
http://icodeblog.com/2009/07/09/integrating-twitter-into-your-applications/
간단한 인증을 사용하지 않을 예정입니까? 대신 oauth를 사용해야합니다. 인터넷 검색 "트위터 oauth 아이폰"안타를 많이 제공합니다. – Rup