Desktop Getting Started
Import MKAbeFook into your XCode project
- Control + click the Frameworks group in XCode and select Add-Existing Framework. Navigate to MKAbeFook.framework and click Add.
- Click Add again to add it to selected targets.
- Control + click your project in the Targets group. Select Add->New Copy Files Build Phase.
- Choose Frameworks as the destination. Close the window.
- Drag MKAbeFook.framework from the Frameworks group to your new Copy FIles Build Phase folder.
Import <MKAbeFook/MKAbeFook.h>where appropriate.
Create a new MKFacebookObject
MKFacebook *facebookConnection = [[MKFacebook facebookWithAPIKey:@"YOUR_API_KEY"
withSecret:@"YOUR_SECRET_KEY"
delegate:self] retain];
withSecret:@"YOUR_SECRET_KEY"
delegate:self] retain];
Display a login window
[facebookConnection showFacebookLoginWindow];
Implement the userLoginSuccessful delegate method
The userLoginSuccessful method will be called after the user logs in and closes the login window.
-(void)userLoginSuccessful
{
NSLog(@"neat");
}
{
NSLog(@"neat");
}
Call a Facebook method
Once you've verified a user has logged in you may start calling other Facebook methods.
NSMutableDictionary *parameters = [NSMutableDictionary alloc] init];
MKFacebookRequest *request = [[[MKFacebookRequest alloc] init] autorelease];
//set up request object
[request setDelegate:self];
[request setFacebookConnection:facebookConnection];
[request setSelector:@selector(gotAlbumList:)];
//set up parameters for request
[parameters setValue:@"facebook.photos.getAlbums" forKey:@"method"];
[parameters setValue:[facebookConnection uid] forKey:@"uid"];
//add parameters to request
[request setParameters:parameters];
//send the request
[request sendRequest];
[parameters release];
MKFacebookRequest *request = [[[MKFacebookRequest alloc] init] autorelease];
//set up request object
[request setDelegate:self];
[request setFacebookConnection:facebookConnection];
[request setSelector:@selector(gotAlbumList:)];
//set up parameters for request
[parameters setValue:@"facebook.photos.getAlbums" forKey:@"method"];
[parameters setValue:[facebookConnection uid] forKey:@"uid"];
//add parameters to request
[request setParameters:parameters];
//send the request
[request sendRequest];
[parameters release];
Implement our selector so we can do something with the response we get from Facebook.
-(void)gotAlbumList:(NSXMLDocument *)xml
{
//check for valid response
if([[xml rootDocument] validFacebookResponse])
{
NSArray *albums = [[xml rootElement] arrayFromXMLElement];
//do something with the array of albums
}else
{
//oh crap we got an error from facebook, lets see what it says
NSLog([xml description]);
}
}
{
//check for valid response
if([[xml rootDocument] validFacebookResponse])
{
NSArray *albums = [[xml rootElement] arrayFromXMLElement];
//do something with the array of albums
}else
{
//oh crap we got an error from facebook, lets see what it says
NSLog([xml description]);
}
}
Upload a photo
Uploading a photo is almost identical to sending any other request. The only extra step is adding a NSImage object to the NSDictionary of parameters that is passed to the MKFacebookRequest object.
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
MKFacebookRequest *photoRequest = [[[MKFacebookRequest alloc] init] autorelease];
[photoRequest setDelegate:self];
[photoRequest setSelector:@selector(uploadedPhoto:)];
[parameters setValue:@"facebook.photos.upload" forKey:@"method"];
//add a NSImage object to the parameters dictionary, key name can be anything
[parameters setObject:<some NSImage object here> forKey:@"image"];
[parameters setValue:@"123456789" forKey:@"aid"];
[parameters setValue:@"Neat." forKey:@"caption"];
[photosRequest setParameters:parameters];
[photoRequest sendRequest];
[parameters release];
MKFacebookRequest *photoRequest = [[[MKFacebookRequest alloc] init] autorelease];
[photoRequest setDelegate:self];
[photoRequest setSelector:@selector(uploadedPhoto:)];
[parameters setValue:@"facebook.photos.upload" forKey:@"method"];
//add a NSImage object to the parameters dictionary, key name can be anything
[parameters setObject:<some NSImage object here> forKey:@"image"];
[parameters setValue:@"123456789" forKey:@"aid"];
[parameters setValue:@"Neat." forKey:@"caption"];
[photosRequest setParameters:parameters];
[photoRequest sendRequest];
[parameters release];
Send multiple requests using a queue
The MKFacebookRequestQueue class can be used to send multiple requests that wait for the previous request to finish before sending a new one. Simply set up individual MKFacebookRequests and add them to a MKFacebookRequestQueue.
//create a MKFacebookRequest instance variable
MKFacebookRequestQueue *requestQueue = [[MKFacebookRequestQueue alloc] init];
[requestQueue setDelegate:self];
/*currentlyUploadingImage: will receive a NSDictionary with a "current" key and a "total" key
to indicate which image is currently being uploaded*/
[requestQueue setCurrentlySendingSelector:@selector(currentlyUploadingImage:)];
/*lastImageUploaded will receive the NSXMLDocument containing the response from
Facebook from the most recent image upload*/
[requestQueue setLastRequestResponseSelector:@selector(lastImageUploaded:)];
//allImagesUploaded will be called after the queue has attempted all requests
[requestQueue setAllRequestsFinishedSelector:@selector(allImagesUploaded)];
//here we set up however many MKFacebookRequest objects we want and add them to the queue
[requestQueue addRequest:request1];
[requestQueue addRequest:request2];
[requestQueue addRequest:request3];
//start processing requests in the queue
[requestQueue startRequestQueue];
//handle responses in appropriate selectors...
MKFacebookRequestQueue *requestQueue = [[MKFacebookRequestQueue alloc] init];
[requestQueue setDelegate:self];
/*currentlyUploadingImage: will receive a NSDictionary with a "current" key and a "total" key
to indicate which image is currently being uploaded*/
[requestQueue setCurrentlySendingSelector:@selector(currentlyUploadingImage:)];
/*lastImageUploaded will receive the NSXMLDocument containing the response from
Facebook from the most recent image upload*/
[requestQueue setLastRequestResponseSelector:@selector(lastImageUploaded:)];
//allImagesUploaded will be called after the queue has attempted all requests
[requestQueue setAllRequestsFinishedSelector:@selector(allImagesUploaded)];
//here we set up however many MKFacebookRequest objects we want and add them to the queue
[requestQueue addRequest:request1];
[requestQueue addRequest:request2];
[requestQueue addRequest:request3];
//start processing requests in the queue
[requestQueue startRequestQueue];
//handle responses in appropriate selectors...