iPhone - How to post image on friend's facebook wall - ios

if ([FBSession.activeSession.permissions indexOfObject:#"publish_actions"] == NSNotFound)
{
// No permissions found in session, ask for it
[FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error)
{
// If permissions granted, publish the story
if (!error)
{
[self postImageToFB] ;
}
}];
}
// If permissions present, publish the story
else
{
[self postImageToFB] ;
}
- (void) postImageToFB
{
NSData* imageData = UIImageJPEGRepresentation(self.image, 90);
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"test", #"message",
imageData, #"source",
nil];
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:#"%#/photos",friendName]
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
NSLog(#"%#",error) ;
if( error == NULL )
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
message:#"Post sucessed!!"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil] ;
[alert show] ;
}
}];
}
I can use - (void) postImageToFB function to post on my own wall when I change [NSString stringWithFormat:#"%#/photos",friendName] to #"me/photos"
But I can't post on my friend's wall , maybe permission is wrong or there are some problem I didn't know ?
I got these error
Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0xc0a7320 {com.facebook.sdk:ErrorInnerErrorKey=Error
Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0xc001ea0 {NSUnderlyingError=0xaa45270 "bad URL", NSLocalizedDescription=bad URL}, com.facebook.sdk:HTTPStatusCode=200}

You cant Post to friends wall from now...
Removing ability to post to friends walls via Graph API We will remove the ability to post to a user's friends' walls via the Graph API. Specifically, posts against [user_id]/feed where [user_id] is different from the session user, or stream.publish calls where the target_id user is different from the session user, will fail. If you want to allow people to post to their friends' timelines, invoke the feed dialog. Stories that include friends via user mentions tagging or action tagging will show up on the friend’s timeline (assuming the friend approves the tag). For more info, see this blog post.
Check this...changes mentioned at facebook developers portal
https://developers.facebook.com/roadmap/completed-changes/#february-2013

From the Link #viswa posted we can read
Removing ability to post to friends walls via Graph API We will
remove the ability to post to a user's friends' walls via the Graph
API. Specifically, posts against [user_id]/feed where [user_id] is
different from the session user, or stream.publish calls where the
target_id user is different from the session user, will fail. If you
want to allow people to post to their friends' timelines, invoke the
feed dialog. Stories that include friends via user mentions tagging or
action tagging will show up on the friend’s timeline (assuming the
friend approves the tag). For more info, see this blog post.
If you want to allow people to post to their friends' timelines, invoke the feed dialog.

Related

List out all Facebook friends in native invite dialogbox in iOS

i'm trying to invite facebook friends in ios. successfully i got the output also. I attached that output image also.
My Question is, here i can see the suggested friends list instead of display my all friends. but while am searching any of friends in search bar, then it display that search list. My code is,
NSString *MY_URL = [NSString stringWithFormat:#"xxxxxxxxxx://host"];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithCapacity:0];
[params setObject:#"Hi, Check out this app, You'll love it!" forKey:#"message"];
[params setObject:MY_URL forKey:#"link"];
[FBWebDialogs presentRequestsDialogModallyWithSession:FBSession.activeSession
message:#"Friends Invite"
title:#"xxxxxxxx"
parameters:params handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
if (!error) {
NSLog(#"Url : %#",resultURL);
NSLog(#"Result : %u",result);
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:#"request"]) {
// User clicked the Cancel button
NSLog(#"User canceled request.");
} else {
// User clicked the Send button
NSString *requestID = [urlParams valueForKey:#"request"];
NSLog(#"Request ID: %#", requestID);
}
}
else
{
NSLog(#"Error : %#",[error localizedDescription]);
}
}];
My point is how can i display all my friends in this invite list itself.
For Facebook Apps registered later than April 2014, you can not access to all friends unless you are implementing a game/canvas app. (if this is your case, you will need to use invitable_friends endpoint)
Otherwise, unfortunately, you will be able to only access users facebook friends who have already signedin to your app.
Note: Even if your app was created before April 2014, all friends will be useless after april 2015.
For more info in facebook developer
New features available in v2.0
Taggable Friends API: We've added a new endpoint called /me/taggable_friends that you can use in order to generate stories that have friends tagged in them, even those friends don't use your app. If you want to use the taggable friends API, your app will require review.
Invitable Friends API: We've added a new endpoint called /me/invitable_friends that you can use to generate a list of friends for someone to invite to your game through a custom interface. This API is only available to apps that are games on Facebook Canvas.

How to get list of Facebook pages managed by a user

I am currently doing an app, in which I need to make the user select one of the Facebook pages from the list of facebook pages the user manages.
I searched and found that, we are able to search the pages by name, but that includes the whole pages in Facebook. I just need the pages that I manage.
Update:
I gave the /me/accounts for getting the pages that I manage. But the resulting data that i get is
2014-05-14 10:22:11.519 fb page[1695:60b] {
data = (
);
}
Here is my code:
[FBRequestConnection startWithGraphPath:#"me/accounts"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
if (!error)
{
NSLog(#"%#",result);
NSDictionary *dict = result;
pagesArray = [dict objectForKey:#"data"];
NSLog(#"%uld", pagesArray.count);
if (pagesArray.count == 0)
{
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:#"No pages Found" message:#"You do not manage any pages" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
[MBProgressHUD hideHUDForView:self.view animated:YES];
}
else{
facebookPageId = [[pagesArray objectAtIndex:0] objectForKey:#"id"];
NSLog(#"%#", facebookPageId);
[self getPage];
[self getPagePosts];
}
}
else
NSLog(#"%#", [error localizedDescription]);
/* handle the result */
}];
I also gave the login permission, like this:
self.loginView.publishPermissions = #[#"manage_pages"];
I also get this warning:
FBSDKLog: FBSession: a permission request for publish or manage permissions contains unexpected read permissions
Take a look at Graph API Reference.
/{user-id}/accounts
returns Facebook pages of which the current user is an admin.
A user access token with manage_pages permission is required, and will only allow the retrieval for that specific person.
You can also try:
/{user-id}/applications/developer/
to get list of apps managed by the user.

How to post a photo to friend's wall (timeline) using Facebook IOS SDK dialog?

How to post a photo to friend's wall like when you post a photo using facebook site (using "Post" form at the top of friend's wall and switched to "Photo" tab). Result should be something like this:
I know how to post a simple post to friend's wall using [FBWebDialogs presentFeedDialogModallyWithSession..] and #"to" parameter. But is there any way to post exactly a photo (with big thumbnail)?
Removing the ability to post to friends' timelines via API
We have found that posting content via API (stream.publish) on a friend's wall lead to a high incidence of user dissatisfaction (hiding content, blocking the app). After the migration period, posting content to friends' timelines via stream.publish will no longer be allowed. Please use the Feed Dialog for posting
// only supports passing a single image
NSArray* images = #[
#{#"url": [UIImage imageNamed:#"my-awesome-meal-photo.jpg"], #"user_generated" : #"true" }
];
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:#"https://example.com/cooking-app/meal/Lamb-Vindaloo.html" forKey:#"meal"];
[action setObject:images forKey:#"image"];
[FBDialogs presentShareDialogWithOpenGraphAction:action
actionType:#"fbsdktoolkit:cook"
previewPropertyName:#"meal"
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];

Facebook iOS App Invite Friends

I am using Facebook SDK to connect Facebook in my app. User can send invitation to their friends. (Using the Requests dialog provided by FB SDK).
https://developers.facebook.com/docs/tutorials/ios-sdk-games/requests/
And I'm trying to keep the friend list clear if the friend is already invited (ever the friend is accepted or not), hide the friend from the list. But I can't find the way to do this. Is there a way to do this?
Facebook documentation is horrible but I found it is possible exclude authenticated friends as follows:
// See https://developers.facebook.com/docs/games/requests/v2.1 for explanation of the possible parameter keys
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
// Optional parameter for sending request directly to user
// with UID. If not specified, the MFS will be invoked
// #"RECIPIENT_USER_ID", #"to",
// Give the action object request information
// #"send", #"action_type",
// #"YOUR_OBJECT_ID", #"object_id",
#"app_non_users", #"filters",
nil];
[FBWebDialogs
presentRequestsDialogModallyWithSession:nil
message:#"Join me!"
title:#"Invite Friends"
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Case A: Error launching the dialog or sending request.
NSLog(#"Error sending request.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// Case B: User clicked the "x" icon
NSLog(#"User canceled request.");
} else {
NSLog(#"Request Sent.");
}
}
}];
#"app_non_users", #"filters", is the important part!
I dont think you can exclude friends that have had the request sent to them but you can suggest friends to populate in that list. Perhaps if you already know who you have sent the request to you can populate the list with the rest of your friends.

Facebook friend's wall posting through ID

I am trying to post on a Facebook friend's wall, I tried these two methods but none work:
1.
//post on wall
NSMutableDictionary *variables = [[NSMutableDictionary alloc]initWithCapacity:1];
[variables setObject:#"v" forKey:#"message"];
[graphref doGraphPost:[NSString stringWithFormat:#"1389799421/feed"] withPostVars:variables];
//post on wall
2.
[_facebook requestWithGraphPath:#"1389799421/feed"
andParams:[NSMutableDictionary dictionaryWithObject:#"test wall post" forKey:#"message"]
andHttpMethod:#"POST"
andDelegate:self];
...and I can't understand why!! On the facebook website I have added the bundle and the permissions.
I am trying to post on a Facebook friend's wall
Facebook recently announced in the developer blog, that posting to another user’s wall through the API will not be possible any more from Feb 2013 on:
Removing ability to post to friends walls via Graph API
We will remove the ability to post to a user's friends' walls via the Graph API. Specifically, posts against [user_id]/feed where [user_id] is different from the session user, or stream.publish calls where the target_id user is different from the session user, will fail. If you want to allow people to post to their friends' timelines, invoke the feed dialog.
So I think it’s pretty useless starting to develop a feature like that now.
First off, you have to open your session with publish permissions. Specifically, you must request the publish_stream permission.
NSArray * permissions = [[NSArray alloc] initWithObjects:#"publish_stream", nil];
return [FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
[self sessionStateChanged:session
state:status
error:error];
}];
If you have publish permissions, you can create and send the request. Make sure you include the access_token as one of the parameters. If you don't, you will get authentication errors.
NSDictionary * postParameters = [NSDictionary dictionaryWithObjectsAndKeys:_textView.text, #"message", FBSession.activeSession.accessToken, #"access_token", nil];
NSString * graphPath = #"ID_NUMBER_HERE/feed";
FBRequest * request = [FBRequest requestWithGraphPath:graphPath parameters:postParameters HTTPMethod:#"POST"];
[[request initWithSession:FBSession.activeSession graphPath:graphPath parameters:postParameters HTTPMethod:#"POST"] startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(#"Successful posted to Facebook");
}];
}

Resources