How to post multiple pictures with an open graph request to facebook? - ios

Code that posts one image:
-(IBAction)postImageToFacebook:(id)sender {
DLog(#"");
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:self.textField.text forKey:#"message"];
DLog(#"%#",[params objectForKey:#"message"]);
if(self.imageView.image){
DLog(#"not null");
UIImage *_img = self.imageView.image;
[params setObject:UIImagePNGRepresentation(_img) forKey:#"picture"];
}
[self performPublishAction:^{
[FBRequestConnection startWithGraphPath:#"me/photos"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
if (error)
{
//showing an alert for failure
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"unable to post"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
else
{
//showing an alert for success
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Posted!"
message:#""
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}];
}];
}
Can I add another object for a duplicate key into the NSMutableDictionary?

Related

Stuck with a lowercase error on signup page

Hello for the life of me I cannot figure out why I am getting the following error during my signup process. Attached is the picture of what I'm getting this error when I enter a uppercase letter inside the username textfield.
Call Signup Fuction:
- (void)signUpCode {
NSString *str = #"09";
str = [_firstNameField.text isEqualToString:#""]?#"Please provide firstname":[_lastNameField.text isEqualToString:#""]?#"Please provide lastname":[_usernameField.text isEqualToString:#""]?#"Please provide username":[_emailField.text isEqualToString:#""]?#"Please provide email":[_passwordField.text isEqualToString:#""]?#"Please provide password":#"";
if ([_passwordField.text isEqualToString:_repeatPasswordField.text]) {
}
else
{
UIAlertView *alt = [[UIAlertView alloc]initWithTitle:#"work" message:#"Password doesn't match." delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
[alt show];
}
if ([str isEqualToString:#""])
{
NSDictionary *dict =[[NSDictionary alloc] initWithObjectsAndKeys:_firstNameField.text,#"firstname",_lastNameField.text,#"lastname",_usernameField.text,#"username",_emailField.text,#"email",_passwordField.text,#"password", nil];
[blkRkMngr signup:dict completionBlock:^(BOOL success){
if (success) {
// Go to main menu
[self performSegueWithIdentifier:#"showMenu" sender:self];
}
else{
}
}];
}
else{
UIAlertView *alt = [[UIAlertView alloc]initWithTitle:#"LoginApp" message:str delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
[alt show];
}
}
Details for Signup
-(void)signup:(NSDictionary *)dictParam completionBlock:(BlackRockManagerCompletionBlock)pCompletionBlock{
NSString *strRequestUrl = KSignup;
[Helper showGlobalProgressHUDWithTitle:#"Loading"];
AFHTTPRequestOperationManager *operationManager = [AFHTTPRequestOperationManager manager];
operationManager.responseSerializer = [AFJSONResponseSerializer serializer];
operationManager.requestSerializer = [AFJSONRequestSerializer serializer];
operationManager.responseSerializer.acceptableContentTypes = [operationManager.responseSerializer.acceptableContentTypes setByAddingObject:#"Text/html"];
AFHTTPRequestOperation *operation = [operationManager POST:strRequestUrl parameters:dictParam success:^(AFHTTPRequestOperation *operation, id responseObject) {
[Helper dismissGlobalHUD];
NSDictionary* dictResponse = [NSJSONSerialization
JSONObjectWithData:operation.responseData //1
options:kNilOptions
error:nil];
NSLog(#"%#",dictResponse);
if ([[dictResponse valueForKey:#"status"] intValue] == 1) {
UIAlertView *alt = [[UIAlertView alloc]initWithTitle:#"Trend" message:[dictResponse valueForKey:#"message"] delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
[alt show];
pCompletionBlock(YES);
}
else if([[dictResponse valueForKey:#"status"] intValue] == 2){
UIAlertView *alt = [[UIAlertView alloc]initWithTitle:#"Trend" message:[dictResponse valueForKey:#"message"] delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
[alt show];
pCompletionBlock(NO);
}else{
UIAlertView *alt = [[UIAlertView alloc]initWithTitle:#"Trend" message:[dictResponse valueForKey:#"message"] delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
[alt show];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[Helper dismissGlobalHUD];
NSLog(#"Failed %#",operation.responseString);
}];
[operation start];
}
It's weird since I also searched everywhere in the entire code and I cannot find where the error box statement of "Username must contains only small letters and numbers".
You can not find out "Username must contains only small letters and numbers" error message because it comes from HTTP request and showed with UIAlertView.
Just checkout the codes where you request and find out why that error occurs.

posting image on facebook wall xcode ios

i am using facebook sdk 3.0 for posting image on facebook wall.
when I am posting image on Facebook wall it is posting only from developer id not any other IDs.
user login from his facebook account to upload photos on his wall.If user login from developer account then image is posting on wall and from other account it is not posting.
-(void)uploadPhoto {
if (FBSession.activeSession.isOpen) {
[self promptUserWithAccountNameForUploadPhoto];
} else {
[FBSession openActiveSessionWithPermissions:permissions
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
if (error) {
} else
if(FB_ISSESSIONOPENWITHSTATE(status))
{
[self promptUserWithAccountNameForUploadPhoto];
}
}];
}
}
-(void)promptUserWithAccountNameForUploadPhoto {
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {
UIAlertView *tmp = [[UIAlertView alloc]
initWithTitle:#"Upload to FB?"
message:[NSString stringWithFormat:#"Upload to ""%#"" Account?", user.name]
delegate:self
cancelButtonTitle:nil
otherButtonTitles:#"No",#"Yes", nil];
tmp.tag = 100;
[tmp show];
}
}];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex==1) {
if (alertView.tag==100) {
[FBRequestConnection startForUploadPhoto:sampleImage
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
UIAlertView *tmp = [[UIAlertView alloc]
initWithTitle:#"Success"
message:#"Photo Uploaded"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:#"Ok", nil];
[tmp show];
} else {
UIAlertView *tmp = [[UIAlertView alloc]
initWithTitle:#"Error"
message:#"Some error happened"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:#"Ok", nil];
[tmp show];
}
}];
}
if (alertView.tag==200) {
[FBRequestConnection startForPostStatusUpdate:myStatus.text completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
UIAlertView *tmp = [[UIAlertView alloc]
initWithTitle:#"Success"
message:#"Status Posted"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:#"Ok", nil];
[tmp show];
} else {
UIAlertView *tmp = [[UIAlertView alloc]
initWithTitle:#"Error"
message:#"Some error happened"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:#"Ok", nil];
[tmp show];
}
}];
}
}
}
In your facebook application you have a option to set on/off developer mode for your application.
If facebook application is not live you can only post with developer accounts

Setting of facebook app for invite friend

It may be an easy question, but I am tired of it
Is there any setting for Facebook app (Which we set while creating an App in Facebook developer's site) for making "invite friend" functionality to be worked.
I am using WebDialog method as follows,
FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:FacebookInviteMessage
title:#"Invite Friends"
parameters:parameters
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
With the same method I am able to invite friend, when I am using the Facebook APP ID of another sample code in my project. But when I am using my own project's Facebook APP ID, invite is not working when I am getting Success in result url.
So I think there would be some setting in developer's site of Facebook.
Can anyone help for this
The complete code is
NSDictionary *parameters = self.fbidSelection ? #{#"to":self.fbidSelection} : nil;
MIDLog(#"self.fbidSelection %#",self.fbidSelection);
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:FacebookInviteMessage
title:#"Invite Friends"
parameters:parameters
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
NSString *strResultUrl = [resultURL absoluteString];
if (result == FBWebDialogResultDialogCompleted && ![strResultUrl isEqualToString:#"fbconnect://success"])
{
MIDLog(#"Web dialog complete: %#", resultURL);
if (![resultURL query])
{
return;
}
NSDictionary *params = [self parseURLParams:[resultURL query]];
NSMutableArray *recipientIDs = [[NSMutableArray alloc] init];
for (NSString *paramKey in params)
{
if ([paramKey hasPrefix:#"to["])
{
[recipientIDs addObject:[params objectForKey:paramKey]];
}
}
if ([params objectForKey:#"request"])
{
NSLog(#"Request ID: %#", [params objectForKey:#"request"]);
}
if ([recipientIDs count] > 0)
{
//[self showMessage:#"Sent request successfully."];
//NSLog(#"Recipient ID(s): %#", recipientIDs);
UIAlertView *alrt = [[UIAlertView alloc] initWithTitle:#"Success!" message:#"Invitation(s) sent successfuly!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alrt show];
alrt = nil;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Success" message:FacebookInviteSuccess delegate:self cancelButtonTitle:#"Proceed" otherButtonTitles:nil];
alert.tag = 14114;
[alert show];
alert = nil;
// [self navigateToSearch];
}
else if (result == FBWebDialogResultDialogCompleted && [strResultUrl isEqualToString:#"fbconnect://success"])
{
MIDLog(#"Cancel Clicked");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Cancelled" message:nil delegate:self cancelButtonTitle:#"Proceed" otherButtonTitles:nil];
alert.tag = 14114;
[alert show];
alert = nil;
}
else {
MIDLog(#"Web dialog not complete, error: %#", error.description);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:InternetFailError delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
alert.tag = 15115;
[alert show];
alert = nil;
}
}
friendCache:self.friendCache];
}
Thank you

Facebook setting for Invite friend in Facebook

It may be an easy question but can anybody tell me.
Is there any setting we need to do in the app (in Facebook developer site) for invite friends?
I have done all in code to invite friends.
When I substitute the Facebook APP ID of a sample code in which invite friend is working, then my code is also working fine.
But when I substitute my APP ID then the process is going fine, showing me successfully invitation message, but invitation is not sent.
I am using the following code:
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:FacebookInviteMessage
title:#"Invite Friends"
parameters:parameters
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
NSString *strResultUrl = [resultURL absoluteString];
if (result == FBWebDialogResultDialogCompleted && ![strResultUrl isEqualToString:#"fbconnect://success"])
{
MIDLog(#"Web dialog complete: %#", resultURL);
if (![resultURL query])
{
return;
}
NSDictionary *params = [self parseURLParams:[resultURL query]];
NSMutableArray *recipientIDs = [[NSMutableArray alloc] init];
for (NSString *paramKey in params)
{
if ([paramKey hasPrefix:#"to["])
{
[recipientIDs addObject:[params objectForKey:paramKey]];
}
}
if ([params objectForKey:#"request"])
{
NSLog(#"Request ID: %#", [params objectForKey:#"request"]);
}
if ([recipientIDs count] > 0)
{
//[self showMessage:#"Sent request successfully."];
//NSLog(#"Recipient ID(s): %#", recipientIDs);
UIAlertView *alrt = [[UIAlertView alloc] initWithTitle:#"Success!" message:#"Invitation(s) sent successfuly!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alrt show];
alrt = nil;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Success" message:FacebookInviteSuccess delegate:self cancelButtonTitle:#"Proceed" otherButtonTitles:nil];
alert.tag = 14114;
[alert show];
alert = nil;
}
else if (result == FBWebDialogResultDialogCompleted && [strResultUrl isEqualToString:#"fbconnect://success"])
{
MIDLog(#"Cancel Clicked");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Cancelled" message:nil delegate:self cancelButtonTitle:#"Proceed" otherButtonTitles:nil];
alert.tag = 14114;
[alert show];
alert = nil;
}
else {
MIDLog(#"Web dialog not complete, error: %#", error.description);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:InternetFailError delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
alert.tag = 15115;
[alert show];
alert = nil;
}
}
friendCache:self.friendCache]
I provided the canvas URL in the application settings under Facebook developer site and It works for me

Publishing an action without using backend server

I am using this code for my facebook request, which posts an image as well as text to the user's feed:
My question is, how can I add a parameter for location? I followed this tutorial: https://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/show-nearby-places/
But I am unable to use a backend server. In the case that I don't want to use a backend server, how can I modify my code to publish a story, including the location (preferably linking to the facebook location) without using a backend server? I have the user selecting the place, and that works flawlessly. Currently I am interested in getting the "at Patxi's Chicago Pizza" to appear without using a backend server. Is this possible?
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:self.textViewForComments.text forKey:#"message"];
//DLog(#"%#",[params objectForKey:#"message"]);
if(self.capturedImageAtFullResolution){
DLog(#"not null");
[params setObject:UIImagePNGRepresentation(self.capturedImageAtFullResolution) forKey:#"picture"];
/*
if(canPostSmileysImage){ //##
//[params setObject:UIImagePNGRepresentation([self takeScreenShot]) forKey:#"picture"];
} else {
}
*/
[self performPublishAction:^{
[FBRequestConnection startWithGraphPath:#"me/photos"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
if (error)
{
//showing an alert for failure
DLog(#"%#",error);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"unable to post"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
else
{
//showing an alert for success
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Posted!"
message:#""
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}];
}];
}

Resources