Change or show privacy setting when using Feed Dialog - ios

My app is posting to facebook with help of Feed Dialog, but unfortunately public audience of my post is only-me. When I'm trying to set privacy key in publish params for friends visibility:
NSMutableDictionary *params =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
#"my app_id", #"app_id",
#"my app name", #"name",
#"some text.", #"caption",
#"some more text.", #"description",
#"web site link", #"link",
#"some picture link", #"picture",
#"ALL_FRIENDS", #"privacy",
nil];
So when adding #"ALL_FRIENDS", #"privacy", I receive an error in Dialog window when I try to publish: Error100 (I'm using incorrect privacy parameter).
So my question is how can I change this parameter or how can I let user to change it Feed dialog window (I'm using 3.5 facebook SDK).
Thanks in advance!

I'm not sure you'll be able to override the Only Me setting that the user has set in their privacy settings. In general, to get past the dialog error, you can try:
#"{'value': 'ALL_FRIENDS'}", #"privacy",
I know this setting works with Graph API posts (ex: me/feed) when I set the privacy level to something less than what the user has specified to be their ceiling. So if their ceiling is Only Me, the post will show up as Only Me. If their ceiling is Friends and I set the privacy to SELF then I get a post that's Only Me.
You can consider using the new Share Dialog (in 3.5.2). It allows the user to select their privacy. The Feed Dialog windows does not have a privacy selector.
For a comparison of the different share options, see https://developers.facebook.com/docs/howtos/share-dialogs-ios-sdk/

OK, so what have I done to solve the problem:
1.I'm closing any active session when my app launches:
FBSession* currentSession = [FBSession activeSession];
if(currentSession) {
[currentSession close];
}
2.Establishing new connection with friends as default audience
[FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (!error && status == FBSessionStateOpen) {
[self publishWithWebDialog];
}else{
NSLog(#"error");
}
}];
3.Calling method for publishing with Feed Dialog:
[self publishWithWebDialog];
The fun part starts when application is launched for the second time :) There is no need to press all that OK buttons and application just opens Feed dialog, by the way this approach also fixes the problem with deleting application in Facebook from users Account Settings - > Apps.

Related

Facebook's "Messaging an Open Graph message" functionality keeps on returning to my app

I'm trying out Facebook's new Messaging an Open Graph message, which means one can now send open graph stories to friends via the Facebook Messenger app.
In my case, I am building an app where people create a playlist and can then invite others to contribute songs to that said playlists. Therefore, an interesting path to take is being able to post an open graph message via Facebook Messenger to one's friends.
I have set up a Create action, a Playlist object and a Create a Playlist story.
The code I use in the iOS app is very close to the one provided as an example by Facebook:
Creating the playlist object:
NSMutableDictionary<FBGraphObject> *object =
[FBGraphObject openGraphObjectForPostWithType:#"vibe-social-music:playlist"
title:#"Sample Playlist"
image:#"https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png"
url:#"http://samples.ogp.me/616101581814728"
description:#""];
Creating the action:
NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];
action[#"playlist"] = object;
Creating the params:
FBOpenGraphActionParams *params = [[FBOpenGraphActionParams alloc]
initWithAction:action
actionType:#"create"
previewPropertyName:#"playlist"];
Calling the 'present message' dialog within the messenger app:
[FBDialogs
presentMessageDialogWithOpenGraphActionParams:params
clientState:nil
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if (error) {
//TODO: Handle errors
NSLog(#"error: %#", error);
} else {
NSLog(#"results: %#", results);
}
}];
As I explained before, the Facebook messenger app opens, but quickly returns back to my application.
I have the Facebook credentials well setup in my Info.plist file.
The one thing is that the action is not yet validated by Facebook. Could that be an issue?
Otherwise, I'm at a loss as to why it won't show an Open Graph story in the Messenger app, and why it always goes back to my application.
Any help would be greatly appreciated, thanks!
Can you confirm you configured a custom story in the Open Graph section of your app settings (and not just the action and object types)?
Also, it looks like the action type is missing your app namespace in the params construction: i.e.,
FBOpenGraphActionParams *params = [[FBOpenGraphActionParams alloc]
initWithAction:action
actionType:#"vibe-social-music:create"
previewPropertyName:#"playlist"];

iOS - Facebook open graph sharing via app is successful, but does not look the way I want it to on Facebook

I have an iPhone app that is used for taking photos. I just finished adding the Facebook sharing functionality to this app.
I went through this entire page here: https://developers.facebook.com/docs/ios/open-graph
I followed all of the instructions, and copied and pasted the code into xcode. The only thing I didn't do was the one part at the very bottom of the page called "Deep Linking", but that is not important right now.
After doing all of this, my app can successfully share an image to facebook. However, it is not being shared the way I need it to.
When I go to my facebook page to see the share, you would never even know it's there. I have to scroll almost half way down the page, and then it's in the bottom left corner.
Here is a screenshot showing where the share is located on my facebook page when viewed on a Desktop computer:
And here is how the share looks when using the Facebook App for the iPhone (I blacked out my name):
These both look terrible. Here are 2 examples of what I want to accomplish.
Here is how a photo from this app called "Frontback" looks when I share it to my page and view on a Desktop computer:
And it looks the same on the Facebook App for the iPhone as well.
The only difference I can tell is that the URL for my shares has "/activity/" in it, where as the Frontback app shares have "photo.php" in their Facebook URL's.
I can't figure out how to get my app's shares to look like the shares from the Frontback app.
Any help is greatly appreciated thank you.
The posts that you created seems meaningful to me. An open-graph feed is always beautiful and more meaningful than the normal feed.
What Frontback post you are seeing is simple photo upload, that's not a feed. I mean it all depends on your requirement, what exactly your app will want to do.
If you just want to show some photos via your app like Frontback, you can avoid open graph and publish photos using the API \POST /photos.
But if you want to give a link that could redirect the user to the app you should use what you are using right now.
Another thing, when you said-
When I go to my facebook page to see the share, you would never even know it's there. I have to scroll almost half way down the page, and then it's in the bottom left corner.
That's the beauty of open-graph, it clubs all the activities of an app in your timeline, not unnecessarily making status updates and flooding your timeline. The stories appear on top in your/your friends wall and the ticker. You can also see the actual story by clicking on the time in the story of your activity log-
(activity log)
(actual story)
- (void)requestPermissionAndPost {
[FBSession.activeSession requestNewPublishPermissions:[NSArray arrayWithObjects:#"publish_actions", #"publish_checkins",nil]
defaultAudience:FBSessionDefaultAudienceEveryone
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
// Now have the permission
[self postOpenGraphAction];
} else {
// Facebook SDK * error handling *
// if the operation is not user cancelled
if (error.fberrorCategory != FBErrorCategoryUserCancelled) {
[self presentAlertForError:error];
}
}
}];
}
- (void)postOpenGraphAction
{
FBRequestConnection *newConnection = [[FBRequestConnection alloc] init];
FBRequestHandler handler =
^(FBRequestConnection *connection, id result, NSError *error) {
// output the results of the request
[self requestCompleted:connection forFbID:#"me" result:result error:error];
};
UIImage *img = imageView.image;
NSString *message = [NSString stringWithFormat:#"%# %# #DealsHype",msg.text,hashtagFromStore];
FBRequest *request=[[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:#"me/photos" parameters:[NSDictionary dictionaryWithObjectsAndKeys:UIImageJPEGRepresentation(img, 0.7),#"source",message,#"message",#"{'value':'EVERYONE'}",#"privacy", nil] HTTPMethod:#"POST"];
[newConnection addRequest:request completionHandler:handler];
[self.requestConnection cancel];
self.requestConnection = newConnection;
[newConnection start];
}
this is the good to upload image with some message .. if you want to upload a big image like Frontback

FBSession.activeSession.permissions does not appear to accurately depict the valid granted permissions

I am observing the following....
I authenticate a user via the following (note that in the completion block I am nslogging the permissions)
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"email", #"publish_actions",
nil];
[FBSession openActiveSessionWithPublishPermissions:permissions
defaultAudience:FBSessionDefaultAudienceFriends
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
NSLog(#"permissions %#",FBSession.activeSession.permissions);
}];
As a user I start up the app and proceed to login w/ FB.
I am presented with a screen that reads "app would like to access your public profile, friend list and email address." and I select "ok"
I am presented with a screen that reads "app would like to post to your friends on your behalf" and I select "skip".
3) The completion block code spits out the permissions as the following
permissions (
email,
"publish_actions"
)
Why is publish_actions listed? If I try to post to FB now through the app it will error out and tell me that I don't have the right permissions......yet I cannot check for this case b/c FBSession.activeSession.permissions tells me that I have the "publish_actions" permission even when in reality I do not.
What am I missing here?
If you were using iOS SDK 3.0, then this was due to a bug in the SDK. See the bug report for more details.
Symptom summary:
After authorizing user with openActiveSessionWithPermissions method, the sessions variable in callback method contains extended permissions that were not allowed by a user.

Facebook request does not return email

No email is outputted from the Facebook request. How do I get this? I need it for my login/signup process
- (void)request:(FBRequest *)request didLoad:(id)result{
NSLog(#"FACEBOOK RESULT %# ", result);
}
This is the initial request:
[facebook requestWithGraphPath:#"me" andDelegate:self];
The email property cannot be obtained without requesting additional permission to obtain it, see https://developers.facebook.com/docs/reference/login/email-permissions/.
My application uses the following code to first check whether the Facebook session is valid (self.facebook is a Facebook object initialized with initWithAppId):
if (![self.facebook isSessionValid]) {
NSArray* permissions = [NSArray arrayWithObjects: #"email", nil];
[self.facebook authorize:permissions];
} else {
// Since we have a valid session we can get the userinfo
[self getFacebookUserInfo];
}
Your application prompt will indicate "Using this app requires: * Your basic info * Your e-mail address" If the user authorizes you to obtain this information your access token returned will have bits in set to allow you to obtain the e-mail address, and the following will work:
-(void)getFacebookUserInfo {
[self.facebook requestWithGraphPath:#"me" andDelegate:self];
}
assuming your -(void)request:(FBRequest *)request didLoad:(id)result method is available (which it appears that it is).
Note that the full flow of SSO (Single Sign On) is not given here in this post, you'll need to go through https://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/#implementsso in detail.
Note also that you may be using a deprecated API for iOS 6, you should look at https://developers.facebook.com/docs/tutorial/iossdk/upgrading-from-2.0-to-3.1/ before going further.
With 2.4 api, parameters are used in order to specify which user data items you are interested in receiving.
E.g.:
FBSDKGraphRequestConnection *connection2 = [[FBSDKGraphRequestConnection alloc] init];
FBSDKGraphRequest *selfRequest = [[FBSDKGraphRequest alloc] initWithGraphPath:#"me?"
parameters:#{#"fields":#"id,name,first_name,last_name,verified,email"}];
[connection2 addRequest:selfRequest
completionHandler:^(FBSDKGraphRequestConnection *innerConnection, NSDictionary *result, NSError *error) {
if (error) {
NSLog(#"%#", error);
return;
}
if (result) {
// get user data
NSMutableDictionary *facebookUserData = [NSMutableDictionary dictionaryWithDictionary:result];
NSLog(#"result=%#", result);
HOWEVER, they apparently messed up big time, as email is NOT CURRENTLY being returned for DEVELOPERS, and currently in development Apps.
Incidentally, it is IMPOSSIBLE to submit bugs on Apps in development, as they require approved apps in the feedback system...
I wonder how do they think we are going to make sure that something works BEFORE submitting an app for approval, or what is the logic of asking for an App Store id of an App which can't be approved BEFORE Facebook integration can be tested to the fullest.
Besides, who is the genius at Facebook who decides to break working code one day from another?

Can't get the Facebook publish_action permission on iOS

I've spent hours on this and can't get it to work. Basically I just want a button in my app that will 'Like' itself on Facebook.
I've created the app on dev Facebook and have an associated App Page.
In my code I request these permissions:
_permissions = [NSArray arrayWithObjects:#"publish_stream", #"publish_actions", #"user_birthday", nil];
I can retrieve a profile picture fine, but when I try to 'Like' using this code:
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
_facebook.accessToken, #"access_token",
nil];
[_facebook requestWithGraphPath:#"329756493773381/og.likes" andParams:params andHttpMethod:#"POST" andDelegate:self];
I get this error response:
(facebookErrDomain error 10000.)" UserInfo=0x20090590 {error={
code = 200;
message = "(#200) Requires extended permission: publish_actions";
type = OAuthException;
}}
When logging in on the app, Facebook asks me for permission to see my birthday, and tell's me it will Post on my behalf but it seems to not get the publish_actions permission.
Is there something i'm missing that I need to do?
I see Temple Run has a Facebook Like button and offers bonus coins for pressing it. This is what I wish to achieve.
EDIT -------
I've changed my permissions to just #"publish_actions", #"user_birthday" and now the auth dialogue says
"This app may post on your behalf, including objects you liked and
more"
which seems to be the publish_actions permission, however I was still getting the error
message = "(#200) Requires extended permission: publish_actions";
I've changed this line:
[_facebook requestWithGraphPath:#"329756493773381/og.likes" andParams:params andHttpMethod:#"POST" andDelegate:selrf];
to this:
[_facebook requestWithGraphPath:#"329756493773381/og.likes" andDelegate:self];
and I do now get a response back, although it doesn't post a 'like'
This is the result response:
{
data = (
);
paging = {
next = "https://graph.facebook.com/329756493773381/og.likes?sdk=ios&sdk_version=2&access_token=BAAGeAp3ZBGwoBAPICjlgB5zK0YECyP8yElf8hJoMrx8Qs4vjeZAK5PlXFAVbGM1JyXHE0wZBvU0aBeCzCUTZBejQgoJ44CAIQsrG64TfrHdxjMqWD&format=json&offset=25&limit=25";
};
}
Any idea what to try next?
EDIT 2 ---------------
I'm making progress with this.
I've added the users id to the graph request like this
NSString *graphPath = [NSString stringWithFormat:#"%#/og.likes",facebookID];
and used these parameters
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"AAAGeAp3ZBGwoBABvKjsPZAoQQNG9cDPJI2v2TI8acyyPSNtm9ZBkfydHqVZAjSKWSbLuvFwxyxSrCts7kFZCnh7Y6f5PFNlWb6smF8XF33wlRZBgfLyhT1", #"access_token",
#"http://samples.ogp.me/329756493773381", #"object",
nil];
and now I get a like showing up on my timeline :-)
I was using the access-token supplied by the Facebook login, but it seems the one supplied by the graph object is different.
Now, the like that i'm seeing has this pattern:
Darren likes object on MyAPP
Is it even possible to have it as
Darren likes MyAPP
with it linking to the app Facebook page?
Thanks
Check if you have done the steps below:
https://developers.facebook.com/docs/opengraph/tutorial/
"Note: The user-prompt for this permission will be displayed in the first screen of the Enhanced Auth Dialog and cannot be revoked as part of the authentication flow." - link
Try this if you havent already:
Auth Dialog -> Configure how Facebook refers users to your app - > Add publish_actions permissions.
https://developers.facebook.com/docs/opengraph/authentication/
"To enable the new Auth Dialog, go to the App Dashboard, and enable the Enhanced Auth Dialog setting in the Advanced section of your app." -link
Hope this helps!
This seems to be the same problem I was having on this SO question:
Facebook iOS SDK 3.0, implement like action on a url?
But if you want to like you facebook page in the app, there is no way to do that in Objective C. Only with the javascript Like button which you can generate here:
https://developers.facebook.com/docs/reference/plugins/like/
The way Temple Run does it is to display the Like button in a web-view, so their like button is actually on their server, this is perhaps an ugly-hack but will work for liking a page.

Resources