用Cocoa读取GMail

时间:2011-11-16 17:34:20

标签: xml cocoa gmail

我整个上午都在尝试这样做。我只想从我的Gmail帐户获取XML Feed: 看起来我有身份验证问题,即使我传递用户名和传递。有没有办法在Objective-C中使用GMail?

- (void) awakeFromNib { 

//go and grab the weather data
NSString *username = @"xxxxxxxxx@gmail.com";
NSString *userpass = @"xxxxxxxxxx";
NSString *urlstring = [NSString stringWithFormat:@"https://%@:%@@gmail.google.com/mail/feed/atom", username, userpass];
NSString *encodedString = [urlstring stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:encodedString];

NSError* error = nil;
NSString* testString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];
NSArray *listItems = [testString componentsSeparatedByString:@","];

[self parseXMLFile:url];
}

- (void) parseXMLFile : (NSURL *) url { 

BOOL success;

if (dataParser) // addressParser is an NSXMLParser instance variable

    [dataParser release];

dataParser = [[NSXMLParser alloc] initWithContentsOfURL:url];

[dataParser setDelegate:self];

[dataParser setShouldResolveExternalEntities:YES];

success = [dataParser parse]; // return value not used

// if not successful, delegate is informed of error

}


- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{            

currentKey = nil;
currentStringValue = nil;
[currentStringValue release];

currentKey = [NSString stringWithFormat: @"%@", elementName];


return;
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
currentStringValue = [[NSString alloc] initWithFormat:@"%@", string];
NSLog(@"%@", currentStringValue);
}

我的部分日志结果:

2011-11-16 12:27:55.986 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.986 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.987 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.987 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.987 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.988 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.988 GoogleDataApp[48759:10b] New to Gmail?
2011-11-16 12:27:55.988 GoogleDataApp[48759:10b] Create an account
2011-11-16 12:27:55.989 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.989 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.989 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.990 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.990 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.990 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.991 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.991 GoogleDataApp[48759:10b] Sign in 
2011-11-16 12:27:55.992 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.992 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.993 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.993 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.993 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.994 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.994 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.995 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.995 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.995 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.996 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.996 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.996 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.997 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.997 GoogleDataApp[48759:10b] Username
2011-11-16 12:27:55.997 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.998 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.998 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.998 GoogleDataApp[48759:10b] 
2011-11-16 12:27:55.999 GoogleDataApp[48759:10b] Password
2011-11-16 12:27:55.999 GoogleDataApp[48759:10b] 

0 个答案:

没有答案