iOS Facebook Posing Photo, URL, Message and Name - ios

I'm trying to post Photo, URL, message and name to Facebook from my iOS application to user's wall. I'm using latest Facebook framework 3.1
I'm using following code:
NSDictionary* dict = #{
#"link" : #"https://www.yahoo.com",
#"picture" : UIImagePNGRepresentation([UIImage imageNamed:#"Default.png"]),
#"message":#"Your message here",
#"name" : prodName,
#"caption" : [NSString stringWithFormat:#"Try the app: %#", prodName],
#"description" : #"Integrating Facebook in ios"
};
[FBRequestConnection startWithGraphPath:#"me/photos" parameters:dict HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSString *alertText;
if (error)
{
NSLog(#"%#",[NSString stringWithFormat: #"error: domain = %#, code = %d", error.domain, error.code]);
alertText = #"Failed to post to Facebook, try again";
} else
{
alertText = #"Posted successfully to Facebook";
}
[[[UIAlertView alloc] initWithTitle:#"Facebook Result" message:alertText delegate:nil cancelButtonTitle:#"OK!" otherButtonTitles:nil] show];
}];
I'm able to post successfully. But I'm seeing in Facebook that, its posting only photo and message and not other details. If I'm using #"me/feed", I'm not even able to post successfully. Facebook is giving error code=5.
How can I post all the details?

"me/feed" requires a url for the "picture" parameter. Please take a look at this link: a previous post on posting a photo on user's wall
Looks like you have to decide whether to use "me/photos" or "me/feed". This link will give you more information and may be a possible way around it.

Related

Facebook "view on ..." text on custom story is not showing

I'm implementing deep linking in an app.
Followed every tutorial I found.
Tested every possible setting.
And the result is: If I post a story with "user_generated": "true", Facebook posts the big photo as it should, but there is no link like "view on Instagram", "view on Foursqare" and so on. So people can't reach the actual object.
Facebook settings:
Display Name, Namespace, App Domains, Site URL, Bundle ID, iPhone Store ID, Deep Linking (ON), Native or desktop app?(ON), Is your App Secret embedded?(OFF)
App Restrictions - No restrictions
I'v set up the open graph action and object and they are working without "user_generated": "true".
I'm sending my code (projectnamespace is replaced for this example):
-(void) shareOnFacebook: (NSString *) image {
NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPost];
object.provisionedForPost = YES;
object[#"type"] = #"projectnamespace:photo";
object[#"title"] = _postText.text;
object[#"url"] = responseJson[#"share"];
object[#"og:url"] = responseJson[#"share"];
object[#"al:web"] = responseJson[#"share"];
object[#"web"] = responseJson[#"share"];
if (image) {
NSLog(#"Photo Link: %#", image);
object[#"image"] = #[#{#"url": image, #"user_generated" : #"true" }];
}
// Post custom object
[FBRequestConnection startForPostOpenGraphObject:object completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSString *objectId = [result objectForKey:#"id"];
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:objectId forKey:#"photo"];
[action setObject: #"true" forKey: #"fb:explicitly_shared"];
if (image)
[action setImage:#[#{#"url": image, #"user_generated" : #"true" }]];
// create action referencing user owned object
[FBRequestConnection startForPostWithGraphPath:#"me/projectnamespace:add" graphObject:action completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSString *actionId = [result objectForKey:#"id"];
NSLog(#"Posted story to facebook: %#", actionId);
[self shareAndDismiss: nil];
} else {
// An error occurred
NSLog(#"Encountered an error posting action to Open Graph: %#", error);
[self shareAndDismiss: nil];
}
}];
} else {
// An error occurred
NSLog(#"Error posting the Open Graph object to the Object API: %#", error);
[self shareAndDismiss: nil];
}
}];
}
As far as I have seen, there is no such "View on Foursquare" link on Foursquare posts being shared on Facebook.
The only "View on..." links that I am aware of are for Instagram. However Instagram is a Facebook company. The Facebook and Instagram teams work together for their own photo-sharing experience, which means they are not limited by the API as we are.
I'm afraid that "View on Instagram" is a special feature given to the Instagram app only and that the Facebook API doesn't give that ability to others apps.

facebook content looks diffrent in wall and home page , after posting the content from iOS app using facebook sdk of iOS

Facebook content looks different in wall and home page , after posting the content from iOS app using facebook sdk of iOS,
Used Code : We are using following code for posting the data in facebook wall.
[NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Found this app ", #"message",
#"AppName", #"name",
#"App Title", #"caption",
#"Description data", #"description",
#"Link URL", #"link",
#"Image URL", #"picture",nil];
// create the connection object.
FBRequestConnection *newConnection = [[[FBRequestConnection alloc] initWithTimeout:kRequestTimeoutInterval] autorelease];
// create the request object, using the fbid as the graph path as an alternative the request* static methods of the
// FBRequest class could be used to fetch common requests, such as /me and /me/friends
FBRequest *request=[[[FBRequest alloc] initWithSession:activeSession
graphPath:#"me/feed"
parameters:params
HTTPMethod:#"POST"] autorelease];
Detail: When we are going to post this data and link url ia available then content are looks different in home screen and profile screen .
Instead od App Name is display the Link URL title in home page but in profile page it display right content like App Title.
It happen only posting from iOS app , it looks good from Android app.
Please help Me tikamchandrakar#gmail.com or tikam.chandrakar#xymob.com
Let me know if any thing is not clear.
Thanks
Try This code. It works Perfect for me -
// Helper method to request publish permissions and post.
- (void)requestPermissionAndPost {
[FBSession.activeSession requestNewPublishPermissions:[NSArray arrayWithObject:#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error && [FBSession.activeSession.permissions indexOfObject:#"publish_actions"] != NSNotFound) {
// Now have the permission
[self postOpenGraphAction];
} else if (error){
// Facebook SDK * error handling *
// if the operation is not user cancelled
if (error.fberrorCategory != FBErrorCategoryUserCancelled) {
// [self presentAlertForError:error];
}
}
}];
}
// Creates the Open Graph Action.
- (void)postOpenGraphAction {
NSString *pageId = #"";
if ([pageIdArray count] > 0) {
pageId = [[pageIdArray objectAtIndex:0] objectForKey:#"page_id"];
}else{
pageId = #"";
}
//http://mistoh.com/mistohws/CategoriesIcon/CategoryIcon_%1$s.png
[FBRequestConnection startWithGraphPath:#"me/feed"
parameters:#{
#"link":#"http://mistoh.com/mistohws/CategoriesIcon/CategoryIcon_1.png",
#"message":[NSString stringWithFormat:#"I just shared a Mistoh at %#",self.mistohNameStr],
#"place":[NSString stringWithFormat:#"%#",pageId],
#"name":[NSString stringWithFormat:#"%#",self.mistohNameStr],
#"description":[NSString stringWithFormat:#"%#",self.mistohDescStr],
#"address":[NSString stringWithFormat:#"%#",self.mistohAddressStr],
#"tags":[NSString stringWithFormat:#"%#",self.selectedFriendsStr]
}
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
//verify result
if (!error) {
[[[UIAlertView alloc] initWithTitle:#"Shared Mistoh Successfully!!"
message:#""
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil]
show];
}else{
[[[UIAlertView alloc] initWithTitle:#"Error"
message:#"Error while sharing mistoh with friends."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil]
show];
NSLog(#"Error : %#",[error description]);
}
}];
}
It looks good on facebook wall and timeline. Thank You..

frictionless sharing using facebook open graph fails intermittently - iOS

When I perform the action I want to show on facebook activities I sometimes get this error code (especially with an object that I haven't previously or recently interacted with):
open graph log: error: domain = com.facebook.sdk, code = 5
upon repeating the action it just eventually works, shows the activity properly on facebook and returns a message that looks like this:
open graph log: Posted Open Graph action, id: 10151538299634942
The open graph information is embedded in pages on our web server and self.recipe.URLatThisApp is the URL for the object. I've been trying to debug this and I'm not sure where the error lies. Would appreciate any pointers.
Note: We just tested this on our website, and the open graph frictionless sharing on the website behaves the same way. So we don't believe that the issue is iOS specific or we are making the same mistake in both our iOS and web implementations.
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[params setObject:self.recipe.URLatThisApp forKey:#"recipe"];
NSLog(#"OPEN GRAPH SAVE");
[FBRequestConnection startWithGraphPath:#"me/ThisAppns:save" parameters:params HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSString *alertText;
if (!error) {
alertText = [NSString stringWithFormat:
#"Posted Open Graph action, id: %#",
[result objectForKey:#"id"]];
} else {
alertText = [NSString stringWithFormat:
#"error: domain = %#, code = %d",
error.domain, error.code];
}
/*
[[[UIAlertView alloc] initWithTitle:#"Result"
message:alertText
delegate:nil
cancelButtonTitle:#"Thanks!"
otherButtonTitles:nil]
show];
*/
NSLog(#"open graph log: %#", alertText);
}
];
}

Errors when posting to a friends feed using FB iOS SDK

Some form of this has been asked/answered before but I'm still pretty hazy on the issue. I'm trying to post to a friends feed but keep getting "error com.facebook.sdk code = 5" errors when trying to use startWithGraphPath: from the new FB SDK for ios. The FBSession is active and open and the access_token appears to be correct... Here's some code:
-(void)inviteUser:(NSString *)whoever {
if ([FBSession.activeSession.permissions indexOfObject:#"publish_actions"] == NSNotFound) {
// No permissions found in session, so ask for it
[FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:#"publish_actions"] defaultAudience:FBSessionDefaultAudienceFriends completionHandler:^(FBSession *session, NSError *error) {
if (!error){
[self sendInvite:whoever];
}
}
}];
}
-(void) sendInvite:(NSString *)whoever {
NSMutableDictionary *params =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
#"A name of something", #"name",
nil];
[FBRequestConnection
startWithGraphPath:[NSString stringWithFormat:#"%#/feed", whoever]
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
NSString *alertText;
if (error) {
alertText = [NSString stringWithFormat:
#"error: domain = %#, code = %d",
error.domain, error.code];
} else {
alertText = #"Posted successfully.";
}
// Show the result in an alert
[[[UIAlertView alloc] initWithTitle:#"Result"
message:alertText
delegate:self
cancelButtonTitle:#"OK!"
otherButtonTitles:nil]
show];
}];
I'm still new at this, and am probably missing something basic. But I'm just not seeing it.
Fixed it. I think there were two problems:
Not having the session properly communicated inside the app (i.e. I had the FBSession open in a loginController, but not in the sendInvite controller <- not the exact names, obviously). As a result, the access_token actually wasn't active. I should have followed the FB docs and put the FBSession methods in the appdelegate.
I was using "publish_action" permissions when I believe I should have been using "publish_stream."
Works smoothly with these two changes. I do have a follow-up question, though: how to post on someone else's wall using the new SDK's native share dialog? I'll probably ask this as a separate question.

Facebook post on news feed and link behind the "name" of the post

I am posting a post on the current user feed with the following code:
NSMutableDictionary *postParams = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
#"http://url.com/image.jpg", #"picture",
#"The title of the post on the feed", #"name",
#"Caption text", #"caption",
#"Description text", #"description", nil];
[self.facebook requestWithGraphPath:#"me/feed" andParams:postParams andHttpMethod:#"POST" andDelegate:nil];
It works great but I can't figure out how to setup the link behind the name of the post ("The title of the post on the feed"). For now the link looks like the following :
https://www.facebook.com/connect/uiserver.php?app_id=[MY_APP_ID]&method=permissions.request&redirect_uri=[THE_URL_OF_THE_PICTURE]&response_type=code&display=page&auth_referral=1
Is there a way to control this url easily? Thanks!
-- EDIT --
Here is a screenshot of a kind of post I want to create :
http://cl.ly/image/020D1z3S2L16.
The link behind the blue title "Je t'ai envoyé un défi dans Années 80" is really clean (just like http://itunes.apple.com/app/[APP_NAME]) and I'd like to do the same.
I believe this not an open graph action, just a basic post. Thanks
All parameters of the Facebook feed are outlined in the Graph API reference, https://developers.facebook.com/docs/reference/api/post/.
The relevant ones are "name", "caption", "description" or "message". Therefore, if whatever is the element you are referring to is not affected, you don't have control over it.
Hey Its very easy just try this code.
NSMutableDictionary *params = [NSMutableDictionary dictionary] ;
[params setObject:#"Test post" forKey:#"message"];
[params setObject:#"link" forKey:#"type"];
[params setObject:#"http://yoursite.com" forKey:#"link"];
[params setObject:#"Link description" forKey:#"description"];
// Make the request
[FBRequestConnection startWithGraphPath:#"/me/feed"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
if(appDelegate.isLoggedInWithTwitter)
{
[self postMessage:_lblTitle.text];
}
else
{
[self toggleProgressHud:NO title:#"" message:#""];
NSLog(#"%#",[NSString stringWithFormat:#"result: %#", result]);
UIAlertView *alertMsg=[[UIAlertView alloc]initWithTitle:nil message:#"Shared Successfully" delegate:self cancelButtonTitle:nil otherButtonTitles:#"Ok", nil];
alertMsg.tag=11;
alertMsg.delegate=self;
[alertMsg show];
}
// Link posted successfully to Facebook
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"%#",[NSString stringWithFormat:#"%#", error.description]);
[self toggleProgressHud:NO title:#"" message:#""];
[self handleAPICallError:error];
}
}];
And here is the result which you want
For now the link looks like the following :
https://www.facebook.com/connect/uiserver.php?app_id=…&method=permissions.request&…
That sounds like you’ve got Authenticated Referrals enabled in your app settings …?
That would explain, why the link points to the Facebook URL with a parameter method=permissions.request embedded.
If so, and that’s not what you want – then turn of Authenticated Referrals.
"xx shared a link" cannot be controlled through a post. Facebook is performing tons of A/B testing to decide what to display...

Resources