iOS Facebook SDK 3.2.1 Feed post error - ios

I am working on iOS App and it has a simple facebook sharing functionality, basically it allows you to share a link to this app by posting in feed.
I am using facebook SDK 3.2.1 this way:
NSMutableDictionary *params =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Test tweet", #"name",
#"Test", #"description",
#"http://myapplink.com",
#"link",
#"http://myapppicture.com/picture.jpg",
#"picture",
nil];
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
NSLog(#"Error publishing story.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
NSLog(#"User canceled story publishing.");
} else {
NSLog(#"No error!");
}
}
}];
The problem is: when this code runs, it brings up facebook login dialog and after I log in, I see this error on screen: "An error occured. Please try again later".
There's nothing logged in console, but if i close this dialogs, it only logs "User canceled story publishing."
Application settings are very basic - I've setup everything just like facebook asked to do:
http://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/
My question is: has anybody came across the same problem? what can be possible solution?
Thanks!

Now this was fairly simple and I feel kinda stupid :)
But anyway, I hope this will help anybody who will be in the same problem.
Generally, I solved the problem by adding one more key-value pair to my "params" dictionary - value #"my_facebook_app_id" for key #"app_id".
So the correct dictionary looks like:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"11111111", #"app_id",
#"Test tweet", #"name",
#"Test", #"description",
#"http://sometestsite", #"link",
#"http://site.com/testimage.jpg", #"picture",
nil];
Facebook SDK says that app_id key is "Required, but automatically specified by most SDKs" - and even though I provided my app_id via MyApp-Info.plist file, it seems like it was not automatically specified (or I did something wrong).
So if you have the same problem, try adding this #"app_id" key - this should help.

Related

Is it possible to share deep links from the iPhone Simulator?

Deep Links
iOS allows apps to open other apps through a framework of custom URL
schemes. Integrating with Facebook allows users to the navigate
directly to your app from the Facebook app via these URLs, which we
will refer to as "deep linking". For example, when your app posts to
Facebook on behalf of its users, it can include one of these URLs, or
deep links, in the post. Then, when the user's friends engage with the
post and they are directed to your app, you will receive this link and
you can process it to decide what view to land them on.
I can share "normal" links from my test app from the iPhone Simulator. Now I want to share deep links from the iPhone Simulator. But as soon as I change the code to use a deep link the sharing process fails.
The sharing works with this set of parameters (Note: The link is an ordinary URL):
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Sharing Tutorial", #"name",
#"Build great social apps and get more installs.", #"caption",
#"Allow your users to share stories on Facebook from your app using the iOS SDK.", #"description",
#"https://developers.facebook.com/docs/ios/share/", #"link",
#"http://i.imgur.com/g3Qc1HN.png", #"picture",
nil];
The sharing does not work with this set of parameters (Now the link is a deep link):
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Sharing Tutorial", #"name",
#"Build great social apps and get more installs.", #"caption",
#"Allow your users to share stories on Facebook from your app using the iOS SDK.", #"description",
#"fbAPPID://authorize#target_url=[MYURL]", #"link",
#"http://i.imgur.com/g3Qc1HN.png", #"picture",
nil];
This is the code I use to actually share the link:
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog([NSString stringWithFormat:#"Error publishing story: %#", error.description]);
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User cancelled.
NSLog(#"User cancelled.");
} else {
// Handle the publish feed callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:#"post_id"]) {
// User cancelled.
NSLog(#"User cancelled.");
} else {
// User clicked the Share button
NSString *result = [NSString stringWithFormat: #"Posted story, id: %#", [urlParams valueForKey:#"post_id"]];
NSLog(#"result %#", result);
}
}
}
}];
This is the error I see when I try to share with the second set of parameters:
I get it just after providing my login credentials. That not very informative. I don't know where to look. Is it even possible to share deep links from the iPhone Simulator?
EDIT: Deep Links and Custom Schemes are documented Facebook App features. There is an optional field for an URL Scheme Suffix in the Facebook Apps Settings page.

Share video link to facebook ios

I am working on a ios app.
I need to share a video link to facebook.Video will save on my server.
I am using below code:-
params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
AppName, #"title",
AppName, #"name",
[NSString stringWithFormat:#"%#",text], #"caption",
composeViewController1.text, #"description",
Path, #"link",
[NSString stringWithFormat:#"%#%#app_icon-DEMO.png",ServerPath,URLImageFolder], #"picture",
nil];
[FBRequestConnection startWithGraphPath:#"/me/feed"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Link posted successfully to Facebook
NSLog(#"result: %#", result);
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"%#", error.description);
}
}];
But i am getting below error from this
Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0xc52be90 {com.facebook.sdk:HTTPStatusCode=500, com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 1500;
"error_subcode" = 1609005;
message = "This link could not be posted.";
type = FacebookApiException;
};
};
code = 500;
But if i try to share static link say "www.google.com" it is working.
My app's flow is :-
User will check mark on facebook button and the feed will share on facebook and my app at the same time.
Thanks for help.
I don't know exactly whats going wrong here, but as far I know Facebook return com.facebook.sdk code=5 the operation couldn't be completed. (com.facebook.sdk error 5.) this error in few cases, like
Session is is not open.
Facebook has detected that you're spamming the system.
Facebook has a defined limit using the SDK.
You don't have permission to do so or wrong publish permission.
The link you have provided is not working. When I tried to open the link it's say
Facebook need to parse your url. May be that's why fb not give you to post the url.

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...

Facebook iOS SDK 3.x feed dialog is gone?

Today I started to use Facebook SDK 3.0 for iOS and I realized that there is no FBDialog class anymore. I've searched developers.facebook.com for some tutorials how I can show feed dialog using new sdk.
We used to write:
[facebook dialog:#"feed" andParams:params andDelegate:self];
But, it seems that all tips talking about dialogs are related to old SDK in developers.facebook.com.
Did anybody implemented feed dialog with new SDK?
Or, should we build our own DialogViewController to represent all UI elements as textFields, send button in order to make FBRequest?!
I've found the answer here:
Feed Dialog - Facebook Developers
Using the same new SDK 3.x we must add deprecated headers into Frameworks:
and change:
#import <FacebookSDK/FacebookSDK.h>
to
#import "Facebook.h"
EDIT (26.02.2013):
Thanks to Andreas, he mentioned in comment, using new SDK 3.2 doesn't required you include deprecated classes anymore:
Improved Web dialog support: This release adds support for integrating
Web dialogs, feed dialog, and requests dialog, without invoking
deprecated headers, making it cleaner and easier to add dialogs into
your app.
Example:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"", #"name",
#"", #"caption",
#"", #"description",
#"https://website.com/share", #"link",
#"http://website.com/iossdk_logo.png", #"picture",
nil];
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Error launching the dialog or publishing a story.
NSLog(#"Error publishing story.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User clicked the "x" icon
NSLog(#"User canceled story publishing.");
} else {
// Handle the publish feed callback
}
}
}];
With Facebook SDK 3.2, you don't need to import deprecated headers anymore. Web-based dialogs can be presented using the FBWebDialogs class:
[FBWebDialogs presentFeedDialogModallyWithSession:nil parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
// ...
}];

Why does Facebook iOS dialog for feed publish disappear after login?

I'm trying to use the Facebook iOS "feed" dialog call to allow my app's user to share something on their Facebook wall. When the facebook app is not installed, it attempts to let them authenticate within the app (presumably using a web view). The issue is that this dialog just disappears once they authenticate. I was expecting the web view to return to the "feed" sharing view.
How do I detect that they authenticated so that I can re-open the feed dialog?
I've added fbDidLogin to my app delegate, but it's not being called. (I wasn't sure if this would normally be called or not, but I read several people recommending this.)
SBJSON *jsonWriter = [SBJSON new];
// The action links to be shown with the post in the feed
NSArray* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
#"More Videos",#"name",#"http://www.example.com/",#"link", nil], nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Test Caption", #"caption",
#"Test Description", #"description",
#"https://s3.amazonaws.com/example/images/test.png",
#"source",
self.video.blogLink, #"link",
#"01234567890123", #"app_id",
actionLinksStr, #"actions",
nil];
[delegate facebook].sessionDelegate = delegate;
[[delegate facebook] dialog:#"feed" andParams:params andDelegate:self];
It turns out the issue is the same as those reporting that the dialog disappears immediately for them. There is a bug in the Facebook SDK in regards to handling error -999, with the solution described in this comment on SO.
I finally realized I was having the same issue (albeit manifesting slightly differently), when I started listening to the FBDialogDelegate's method:
- (void)dialog:(FBDialog*)dialog didFailWithError:(NSError *)error
The error description referenced the -999 error mentioned above, leading me to the answer. Luckily the code checked into github worked flawlessly. I just had to pull it into the SDK codebase and recompile the .a lib file, then include it into my project.
Did you implemented facebook protocol FBSession in your view controller ?
To detect that user is authenticated you have to call isSessionValid:
if (![[self.fbAppDelegate facebook] isSessionValid]) {
NSArray *permissions = [[NSArray alloc] initWithObjects:#"publish_stream",#"create_event",#"offline_access", nil];
[[self.fbAppDelegate facebook] authorize:permissions];
}
and authorize inApp:
[self authorizeWithFBAppAuth:NO safariAuth:NO];

Resources