views:

3128

answers:

4

After looking I did come accross this post on the facebook forums:

link

They are feeding the facebook object a UIImage. That seems logical, but where is this documented? The API documentation is generalized to all platforms. Where are the iPhone specific requirements for arguments and their data types?

Thanks

**Update***** I still have not came across any API docs pertaining to Cocoa. I did, however, gather the information I needed by piecing together forum information, Facebook sample code, and some glue.

Hopefully they'll issue something a little more concrete over the next few months.

A: 

Joe Hewitt (the author of the Facebook iPhone app) released large parts of the Facebook application as his Three20 framework. It is hosted on github.

Roger Nolan
I have seen that, but I am talking specifically about the iPhone Facebook Connect libraries. These isn't any documentation regarding what data types to provide to the methods.
Corey Floyd
A: 

Hey Cory,

If you don't mind, could you post what you found out? I've been banging my head against my keyboard trying to do the same thing (I think). All sample/forum code seems to be partial at best, and the documentation is severely lacking.

Any help would be great.

  • Andrew
I did post a better answer quite a bit later
Corey Floyd
+5  A: 

For completeness:

The following explains how to interact with Facebook Connect: http://wiki.developers.facebook.com/index.php/Facebook%5FConnect%5Ffor%5FiPhone#Using%5Fthe%5FAPI

The API calls: http://wiki.developers.facebook.com/index.php/API

If you need extended Permissions: http://wiki.developers.facebook.com/index.php/Extended%5Fpermissions

A nice Obj-C wrapper on Mobile Orchard: http://www.mobileorchard.com/marketing-in-code-part-2-setting-a-users-status-in-facebook-from-an-iphone-app-a-tutorial/

What follows is my implementation of a SessionViewController:

#import "SessionViewController.h"
#import "FBConnect.h"
#import "FBFeedDialog.h"

///////////////////////////////////////////////////////////////////////////////////////////////////
// This application will not work until you enter your Facebook application's API key here:

static NSString* kApiKey = @"XXXXXXXXXXXXXXXXXX";

// Enter either your API secret or a callback URL (as described in documentation):
static NSString* kApiSecret = @"XXXXXXXXXXXXXXXXXX"; // @"<YOUR SECRET KEY>";

///////////////////////////////////////////////////////////////////////////////////////////////////

@implementation SessionViewController

@synthesize label = _label;
@synthesize anImage;

- (void)done:(id)sender{

    [self dismissModalViewControllerAnimated:YES];


}

///////////////////////////////////////////////////////////////////////////////////////////////////
// NSObject

- (id)init {
    if (self = [super init]) {
        _session = [[FBSession sessionForApplication:kApiKey secret:kApiSecret delegate:self] retain];
    }
    return self;
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  if (self = [super initWithNibName:@"SessionViewController" bundle:nibBundleOrNil]) {
      _session = [[FBSession sessionForApplication:kApiKey secret:kApiSecret delegate:self] retain];

  }
  return self;
}

- (void)dealloc {
    [_session release];
    [anImage release];
    [super dealloc];
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// UIViewController

- (void)viewDidLoad {
  [_session resume];
  _loginButton.style = FBLoginButtonStyleWide;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  return NO;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// FBDialogDelegate

- (void)dialog:(FBDialog*)dialog didFailWithError:(NSError*)error {
  _label.text = [NSString stringWithFormat:@"Error(%d) %@", error.code,
    error.localizedDescription];
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// FBSessionDelegate

- (void)session:(FBSession*)session didLogin:(FBUID)uid {
  _permissionButton.hidden = NO;
  _feedButton.hidden = NO;

  NSString* fql = [NSString stringWithFormat:
    @"select uid,name from user where uid == %lld", session.uid];

  NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"];
  [[FBRequest requestWithDelegate:self] call:@"facebook.fql.query" params:params];
}

- (void)sessionDidLogout:(FBSession*)session {
  _label.text = @"";
  _permissionButton.hidden = YES;
  _feedButton.hidden = YES;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// FBRequestDelegate

- (void)request:(FBRequest*)request didLoad:(id)result {

    if([result isKindOfClass:[NSArray class]]){
        NSArray* users = result;
        NSDictionary* user = [users objectAtIndex:0];
        NSString* name = [user objectForKey:@"name"];
        _label.text = [NSString stringWithFormat:@"Logged in as %@", name];
    }  

}

- (void)request:(FBRequest*)request didFailWithError:(NSError*)error {
  _label.text = [NSString stringWithFormat:@"Error(%d) %@", error.code,
    error.localizedDescription];
}

///////////////////////////////////////////////////////////////////////////////////////////////////

- (IBAction)askPermissionForPhotoUpload:(id)target {
    FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] init] autorelease];
    dialog.delegate = self;
    dialog.permission = @"photo_upload";
    [dialog show];
}
- (IBAction)publishPhoto:(id)target{

    NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease];
    [args setObject:self.anImage forKey:@"image"];  
    FBRequest *uploadPhotoRequest = [FBRequest requestWithDelegate:self];
    [uploadPhotoRequest call:@"photos.upload" params:args];
}


- (void)askPermission:(id)target {
  FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] init] autorelease];
  dialog.delegate = self;
  dialog.permission = @"status_update";
  [dialog show];
}

- (void)publishFeed:(id)target {
  FBFeedDialog* dialog = [[[FBFeedDialog alloc] init] autorelease];
  dialog.delegate = self;
  dialog.templateBundleId = 9999999;
  dialog.templateData = @"{\"key1\": \"value1\"}";
  [dialog show];
}

@end
Corey Floyd
A: 

Cory- Excellent thread. Thanks for posting it. An issue I am having is uploading video. Would you be willing to take a look at my code and help trouble shoot it? What is the key value for the args NSMutableDicitonary when uploading video (publishPhoto: method)?

Thanks for the help! Chad

SliceofPy
if you post a question, on SO, maybe I can help better.
Corey Floyd
thanks Corey. I posted my question and code at the following link:http://stackoverflow.com/questions/3104660/trying-to-upload-video-to-facebook-using-fbconnect-for-iphoneThanks for looking. I appreciate it.
SliceofPy