Sandeep Singh
Sandeep Singh

Reputation: 826

How to post a photos on facebook through iPhone app?

I am trying to post image on facebook but not successful yet, my codes are:

- (void)postToWall{

int im = 1;
NSData *myimgData; 
myimgData = [NSData dataWithContentsOfFile:saveImagePath];
//pstimg = myimgData;
NSArray *chunks = [pstimg componentsSeparatedByString: @"."];
NSString *atch= [chunks objectAtIndex: 0];



NSString *filePath = [[NSBundle mainBundle] pathForResource:atch ofType:@"jpg"];  


img  = [[UIImage alloc] initWithContentsOfFile:filePath];

//start

FBDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];

NSString *str = @"Hello"; 
str = [str stringByReplacingOccurrencesOfString:@" " withString:@"+"];
dialog.cMessage=str;

dialog.userMessagePrompt = @"Enter your message:";


[dialog show];

NSData * findata;


    //edited from here


    if(im==1)
    {
        findata = myimgData;    

    }
    else
    {
        findata  = (NSData *)img;   

    }

    NSMutableDictionary * param = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   img, @"picture",
                                   nil];

    FBRequest *uploadPhotoRequest =[FBRequest requestWithDelegate:self] ;
    [uploadPhotoRequest call:@"facebook.photos.upload" params:param dataParam:myimgData];



    [img release];

}

But it not posted.

Upvotes: 0

Views: 1112

Answers (1)

Matteo Alessani
Matteo Alessani

Reputation: 10412

To post a photo on Facebook you need to use the iOS SDK from Facebook:

https://github.com/facebook/facebook-ios-sdk

There you'll find sample app with authentication and much more, like posting a photo.

Upvotes: 1

Related Questions