Permalink
Browse files

Merge pull request #11 from vytis/raw_request_data

Raw request data

Added another key to the result dictionary to contain the raw data of the request. Now it is possible to get at binary data like a profile picture.
 
Updated the sample app so that after the token is requested the user's profile picture is displayed.
  • Loading branch information...
2 parents e95a5db + aa04686 commit 522bda22836fcd56f04d5b7da9fc9f2ce727fa86 @philippec committed Jun 4, 2011
Showing with 694 additions and 65 deletions.
  1. +1 −0 classes/PhFacebook.m
  2. +2 −0 sample/FacebookTestAppDelegate.h
  3. +13 −4 sample/FacebookTestAppDelegate.m
  4. +678 −61 sample/en.lproj/MainMenu.xib
@@ -180,6 +180,7 @@ - (void) sendFacebookRequest: (NSDictionary*) allParams
NSDictionary *result = [NSDictionary dictionaryWithObjectsAndKeys:
str, @"result",
request, @"request",
+ data, @"raw",
self, @"sender",
nil];
[_delegate performSelectorOnMainThread:@selector(requestResult:) withObject: result waitUntilDone:YES];
@@ -17,6 +17,7 @@
NSTextField *request_label;
NSTextField *request_text;
NSTextView *result_text;
+ NSImageView *profile_picture;
NSButton *send_request;
NSWindow *window;
}
@@ -25,6 +26,7 @@
@property (assign) IBOutlet NSTextField *request_label;
@property (assign) IBOutlet NSTextField *request_text;
@property (assign) IBOutlet NSTextView *result_text;
+@property (assign) IBOutlet NSImageView *profile_picture;
@property (assign) IBOutlet NSButton *send_request;
@property (assign) IBOutlet NSWindow *window;
@@ -15,6 +15,7 @@ @implementation FacebookTestAppDelegate
@synthesize request_label;
@synthesize request_text;
@synthesize result_text;
+@synthesize profile_picture;
@synthesize send_request;
@synthesize window;
@@ -54,19 +55,27 @@ - (void) tokenResult: (NSDictionary*) result
[self.request_text setEnabled: YES];
[self.send_request setEnabled: YES];
[self.result_text setEditable: YES];
+ [fb sendRequest: @"me/picture"];
}
else
{
[self.result_text setString: [NSString stringWithFormat: @"Error: {%@}", [result valueForKey: @"error"]]];
}
-
}
- (void) requestResult: (NSDictionary*) result
{
- [self.send_request setEnabled: YES];
-
- [self.result_text setString: [NSString stringWithFormat: @"Request: {%@}\n%@", [result objectForKey: @"request"], [result objectForKey: @"result"]]];
+ if ([[result objectForKey: @"request"] isEqualTo: @"me/picture"])
+ {
+ NSImage *pic = [[NSImage alloc] initWithData: [result objectForKey: @"raw"]];
+ self.profile_picture.image = pic;
+ [pic release];
+
+ } else
+ {
+ [self.send_request setEnabled: YES];
+ [self.result_text setString: [NSString stringWithFormat: @"Request: {%@}\n%@", [result objectForKey: @"request"], [result objectForKey: @"result"]]];
+ }
}
- (void) willShowUINotification: (PhFacebook*) sender
Oops, something went wrong.

0 comments on commit 522bda2

Please sign in to comment.