I’m using this code to parse XML in the instance variable response:
@implementation Delegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
MKFacebook *fbConnection = [[MKFacebook facebookWithAPIKey:@"----" delegate:self] retain];
[fbConnection login];
NSMutableDictionary *parameters = [[[NSMutableDictionary alloc] init] autorelease];
MKFacebookRequest *request = [MKFacebookRequest requestWithDelegate:self];
//set up parameters for request
[parameters setValue:[NSArray arrayWithObjects:[fbConnection uid], @"123456789", nil] forKey:@"uids"];
[parameters setValue:[NSArray arrayWithObjects:@"first_name",@"last_name",nil] forKey:@"fields"];
//send the request
[request sendRequest:@"users.getInfo" withParameters:parameters];
}
-(void)userLoginSuccessful
{
NSLog(@"neat");
}
- (void)facebookRequest:(MKFacebookRequest *)request responseReceived:(NSString *)response
{
CFStringRef response = (CFStringRef)response;
NSData *xmlData = [[NSData alloc] initWithData:[response2 dataUsingEncoding:NSUTF8StringEncoding]];
NSXMLParser *parser = [[[NSXMLParser alloc] initWithData:xmlData] autorelease];
[parser setDelegate:self];
[parser parse];
}
But, I am getting this console error upon executing the code:
2010-08-12 20:24:46.924 App[2966:a0f] -[NSXMLDocument dataUsingEncoding:]: unrecognized selector sent to instance 0x47c250
Thanks in advance 🙂
It seems like you are implementing the delegate method incorrectly. According to the MKAbeFook documentation, the signature should be:
where
responseis anNSArrayorNSDictionaryif you specified JSON response type. Since you seem to be getting anNSXMLDocument, it must be defaulting to XML response type. The XML is already parsed and turned in to a DOM, so you don’t need to parse it. Just cast the response and go to work with the NSXML tree-based API.