Posting an image to facebook in iPhone - iphone

Hi I am using this piece of code to post an image to facebook
UIImage *image_LocalSharePhoto = [[UIImage alloc]initWithData:sharedSingleton.dataResultImage];
NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
#"Put Captions On Pics", #"name",
#"Put Captions On Pics", #"caption",
image_LocalSharePhoto,#"picture",
#"I created this fun photo using a FREE app http://bit.ly/CapsPics. #PutCapsOnPics via #PutCapsOnPics", #"description",
nil];
NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"532872463436844", #"api_key",
#"Share on Facebook", #"user_message_prompt",
attachmentStr, #"attachment",
nil];
[facebook dialog: #"feed" andParams:params andDelegate:self];
It opens up facebook page but do not show anything to share or post. Can some one help. Thanks!

if you are using facebook's api , I am able to share the images on user's timeline using following code ... Please review the code if it can help ..
include
// aryFetchedImages = Array of images which needs to be posted on Facebook
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
for (int i = 0; i < aryFetchedImages.count ; i++)
{
[params setObject:UIImageJPEGRepresentation([aryFetchedImages objectAtIndex:i], 50.0f) forKey:#"picture"];
[FBRequestConnection startWithGraphPath:#"me/photos"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
if (error)
{
//showing an alert for failure
#ifdef DEBUG
NSLog(#"Unable to share the photo please try later - Fail %#",error);
#endif
}
else
{
//showing an alert for success
#ifdef DEBUG
NSLog(#"Photo %# uploaded on Facebook Successfully",UIImageJPEGRepresentation([aryFetchedImages objectAtIndex:i], 50.0f));
#endif
}
}];
}

if you are using old facebook Method you can wall post like bellow Methid:-
NSArray* permissions = [NSArray arrayWithObjects:#"publish_stream", #"user_photos", nil];
[facebook authorize:permissions];
now to Post image At your Button Click or your logic like:-
-(IBAction)ActionPostWallPhoto
{
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
ImageView.image, #"picture",
nil];
[[objAppdele facebook] requestWithGraphPath:#"me/feed" andParams:params andHttpMethod:#"POST" andDelegate:self];
}
and if you are using new facebook API then you can use bellow Method:-
NSMutableDictionary *postTest = [[NSMutableDictionary alloc]init];
[postTest setObject:[NSString stringWithFormat#"Your message"] forKey:#"message"];
[postTest setObject:#"" forKey:#"picture"];
[postTest setObject:#"" forKey:#"name"];
[postTest setObject:#"APPID" forKey:#"app_id"];
NSString *userFBID =[NSString stringWithFormat:#"%#",[allInfoDict objectForKey:#"Friends facebook ID "]];
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:#"%#/feed?access_token=%#",userFBID,[appDelegate.mysession accessToken]]
parameters:postTest
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
NSDictionary * result,
NSError *error) {
if (error) {
NSLog(#"Error: %#", [error localizedDescription]);
} else {
// Success
}
}];
[postTest release];

Related

What facebook api I can use to post image,text and link to wall on background

I don't want to use graph story. But all other methods are rejected by Facebook team with message: Please make sure you are not pre-filling message field.
for example:
NSMutableDictionary *params = [NSMutableDictionary dictionary];
[params setObject:text forKey:#"message"];
[params setObject:#"link" forKey:#"type"];
//[params setObject:#"http://google.com/" forKey:#"link"];
if(photoID) {
[params setObject:photoID forKey:#"object_attachment"];
}
FBRequestConnection *connection = [[FBRequestConnection alloc] init];
NSMutableDictionary* photosParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:
image,#"source",
text,#"message",
nil];
FBRequest *request = [[FBRequest alloc] initWithSession:[FBSession activeSession]
graphPath:#"me/photos"
parameters:photosParams
HTTPMethod:#"POST"];
[connection addRequest:request completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
completionBlock(error);
}];
FBRequest *req = [FBRequest requestForGraphPath:#"me/feed"];
req.graphObject = (id<FBGraphObject>)[NSDictionary dictionaryWithDictionary:params];
[connection addRequest:req
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error && result) {
NSLog(#"%#",result);
}
}
];
Please explain what method I should use in this case?
In case if correct behavior is use stories then why other methods are not marked as deprecated?
Thanks.

Cannot POST to app_link_hosts. Permissions error

I am getting "permissions error" message when try to publish to app_link_hosts edge. Please advise me what am I doing wrong? I have checked Facebook permissions. I do have publish_actions permission and I can publish to user's wall no problem but cannot publish to app_link_hosts... Trying to set up a back link from a share link to my iOS app.
NSString *fbAccessToken = [[[FBSession activeSession] accessTokenData] accessToken];
NSString *theUrl = [NSString stringWithFormat:#"myscheme://deeplink?playlist_id=%#",[postParams objectForKey:#"playlist_id"]];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
#"MY APP NAME", #"name",
theUrl, #"al:iphone:url",
#"77948767", #"al:iphone:app_store_id",
#"MY APP NAME", #"al:iphone:app_name",
#"{\"should_fallback\": false}", #"web",
fbAccessToken, #"access_token",
nil
];
/* make the API call */
[FBRequestConnection startWithGraphPath:#"/233246787764/app_link_hosts"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
/* handle the result */
NSLog(#"Result = %#",result);
if(error) NSLog(#"error = %#",error);
}];

Facebook share passs link in app name

I want to pass a link in App Name for example if user click on text via (App Name) then it navigate some specific url
If anybody can help my code is here:
Facebook *fb = [[Facebook alloc] initWithAppId:FB_ID andDelegate:self];
NSString *strUrl = [dicItemDetails valueForKey:#"imgurl"];
if ([strUrl length] == 0) {
strUrl = [[temp objectAtIndex:0] valueForKey:#"logourl"];
}
NSMutableDictionary *d = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
[dicItemDetails valueForKey:#"menuItemName"], #"name"
, strCaption,#"description"
, strUrl, #"picture"
, [[temp objectAtIndex:0] valueForKey:#"facebook"], #"link"
, nil];
[fb dialog:#"feed" andParams:d andDelegate:self];
you can post two link with your Message posting in facebook time line like bellow way:-
-(void)fbNewuserWallpost
{
SBJSON *jsonWriter = [[SBJSON new] autorelease];
NSArray* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
#"AppName",#"name",self.FirstLinkString,#"link", nil], nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"yourAppID",#"app_id",
#"AppName", #"name",
captonString, #"caption",
#"yourDiscription", #"description",
self.secondLinkString, #"link",
#"ImageURL", #"picture",
actionLinksStr, #"actions",
nil];
[[AppDelegate facebook] requestWithGraphPath:#"me/feed" andParams:params andHttpMethod:#"POST" andDelegate:self];
}

How to send message to selected facebook friend in ios 6 with Facebook sdk 3.1?

In my application I'm getting friend list of logged in user and by selecting any one I can get his details like name, photo, id etc.
But my question is that I need to send message to selected user by using his details like id with Facebook SDK 3.1.
if you want to post to users wall try this one :
NSMutableDictionary *postTest = [[NSMutableDictionary alloc]init];
[postTest setObject:[NSString stringWithFormat#"Your message"] forKey:#"message"];
[postTest setObject:#"" forKey:#"picture"];
[postTest setObject:#"" forKey:#"name"];
[postTest setObject:#"APPID" forKey:#"app_id"];
NSString *userFBID =[NSString stringWithFormat:#"%#",[allInfoDict objectForKey:#"Friends facebook ID "]];
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:#"%#/feed?access_token=%#",userFBID,[appDelegate.mysession accessToken]]
parameters:postTest
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
NSDictionary * result,
NSError *error) {
if (error) {
[self hideHUD];
NSLog(#"Error: %#", [error localizedDescription]);
} else {
// Success
}
}];
[postTest release];

iPhone post images to Facebook Feed

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
photoDescription, #"message",
image, #"image",
nil];
[facebook requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
This is what I did to upload a image to Facebook. The image is uploaded successfully to FaceBook 'photos'. But I want to post the image to my FaceBook Feed. So i tried,
[facebook requestWithGraphPath:#"me/feed"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
but it still the images posted to the 'photos'. It does not appear in the Feed...
I searched and used different methods for a solution, but I couldn't find anything helpful...
Not sure what your params looks like, but try this..
UIImage *image = ...// some image.
NSData *imageData= UIImagePNGRepresentation(image);
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"some message", #"message", imageData,#"source", nil];
[facebook dialog:#"feed" andParams:params andDelegate:self];
UIImage* image=...;
if ([FBSession.activeSession.permissions
indexOfObject:#"publish_actions"] == NSNotFound) {
NSArray *permissions =
[NSArray arrayWithObjects:#"publish_actions",#"publish_stream", nil];
[[FBSession activeSession] requestNewPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {}];
}
else
{
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:#"Photo post test..." forKey:#"message"];
[params setObject:UIImagePNGRepresentation(image) forKey:#"picture"];
//for not allowing multiple hits
[FBRequestConnection startWithGraphPath:#"me/photos"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
if (error)
{
//showing an alert for failure
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Post Failed"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
else
{
//showing an alert for success
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Post success"
message:#"Shared the photo successfully"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}];
}