Post on personal Facebook wall using ios sdk and tag multiple friends at once..? - iphone

I am trying to post a message on my wall and wanted to tag multiple users at a time in this post. I tried the various options on the FB post page but couldn't do it. May be I am not doing it right. Any help is appreciated and this is how I am doing it...
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Test 2",#"message",
#"100004311843201,1039844409", #"to",
nil];
[self.appDelegate.facebook requestWithGraphPath:#"me/feed" andParams:params andHttpMethod:#"POST" andDelegate:self];
I have also tried message_tags but that doesn't seem to work as well.

You would need to use Open Graph to tag people with a message. The me/feed Graph API endpoint doesn't support this.
Mentions Tagging
https://developers.facebook.com/docs/technical-guides/opengraph/mention-tagging/
Action Tagging:
https://developers.facebook.com/docs/technical-guides/opengraph/publish-action/
You can take a look at the Scrumptious sample app that comes included with the latest Facebook SDK for iOS to see how to do this.

To tag a friend in ur fb status ..you need "facebook id" of your friend by using FBFriendPickerViewController and "place id" using FBPlacePickerViewController. Following code will help you.
NSString *apiPath = nil;
apiPath = #"me/feed";
if(![self.selectedPlaceID isEqualToString:#""]) {
[params setObject:_selectedPlaceID forKey:#"place"];
}
NSString *tag = nil;
if(mSelectedFriends != nil){
for (NSDictionary *user in mSelectedFriends) {
tag = [[NSString alloc] initWithFormat:#"%#",[user objectForKey:#"id"] ];
[tags addObject:tag];
}
NSString *friendIdsSeparation=[tags componentsJoinedByString:#","];
NSString *friendIds = [[NSString alloc] initWithFormat:#"[%#]",friendIdsSeparation ];
[params setObject:friendIds forKey:#"tags"];
}
FBRequest *request = [[[FBRequest alloc] initWithSession:_fbSession graphPath:apiPath parameters:params HTTPMethod:#"POST"] autorelease];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
[SVProgressHUD dismiss];
if (error) {
NSLog(#"Error ===== %#",error.description);
if (_delegate != nil) {
[_delegate facebookConnectFail:error requestType:FBRequestTypePostOnWall];
}else{
NSLog(#"Error ===== %#",error.description);
}
}else{
if (_delegate != nil) {
[_delegate faceboookConnectSuccess:self requestType:FBRequestTypePostOnWall];
}
}

If you followed the tutorial on how to setup Open Graph for iOS, you can do something like this if you use the friendsPickerController:
// Create an action
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
//Iterate over selected friends
if ([friendPickerController.selection count] > 0) {
NSMutableArray *temp = [NSMutableArray new];
for (id<FBGraphUser> user in self.friendPickerController.selection) {
NSLog(#"Friend selected: %#", user.name);
[temp addObject:[NSString stringWithFormat:#"%#", user.id]];
}
[action setTags:temp];
}
Basically, you can set an array of friend's ids on the "tags" property on an action

Related

How to get list to whom feed is post through facebook

Through facebook, I post message on wall using feed dialog box. I want to get list of friends to whom feed is send.
When user select option to share message on specific group of friends, then privacy has value of enum{EVERYONE, ALL_FRIENDS, FRIENDS_OF_FRIENDS, CUSTOM, SELF}.
My question is how to find facebook user id of above list.
Please help me.
Thanks In Advance.
NSLog(#"%#",[app.Arr_Facebook_Frnd objectAtIndex:indexpath]);
NSString *userid = [[app.Arr_Facebook_Frnd objectAtIndex:indexpath] objectForKey:#"id"];
NSString *str_name = [[app.Arr_Facebook_Frnd objectAtIndex:indexpath] objectForKey:#"name"];
NSString *str_link = #"www.google.com";
NSDictionary *params = #{
#"name" : str_name,
#"caption" : #"",
#"description" : #"",
#"picture" : #"",
#"link" : str_link,
#"to":userid,
};
/
// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
NSLog(#"Error publishing story.");
[self.indicator stopAnimating];
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
NSLog(#"User canceled story publishing.");
[self.indicator stopAnimating];
} else {
NSLog(#"Story published.");
[self.indicator stopAnimating];
}
}}];

How to post to a users wall using Facebook SDK

I want to post some text to a users wall using the facebook sdk in an iOS app.
Is posting an open graph story now the only way to do that?
I've found with open graph stories they are really strange, you can only post things in the format "user x a y" where you preset x and y directly on facebook, like user ata a pizza or user played a game. Setting up each one is pretty laborious too because you have to create a .php object on an external server for each one.
Am I missing something or is there a simpler way to go about this?
Figured it out by browsing the facebook tutorials a bit more.
-(void) postWithText: (NSString*) message
ImageName: (NSString*) image
URL: (NSString*) url
Caption: (NSString*) caption
Name: (NSString*) name
andDescription: (NSString*) description
{
NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
url, #"link",
name, #"name",
caption, #"caption",
description, #"description",
message, #"message",
UIImagePNGRepresentation([UIImage imageNamed: image]), #"picture",
nil];
if ([FBSession.activeSession.permissions indexOfObject:#"publish_actions"] == NSNotFound)
{
// No permissions found in session, ask for it
[FBSession.activeSession requestNewPublishPermissions: [NSArray arrayWithObject:#"publish_actions"]
defaultAudience: FBSessionDefaultAudienceFriends
completionHandler: ^(FBSession *session, NSError *error)
{
if (!error)
{
// If permissions granted and not already posting then publish the story
if (!m_postingInProgress)
{
[self postToWall: params];
}
}
}];
}
else
{
// If permissions present and not already posting then publish the story
if (!m_postingInProgress)
{
[self postToWall: params];
}
}
}
-(void) postToWall: (NSMutableDictionary*) params
{
m_postingInProgress = YES; //for not allowing multiple hits
[FBRequestConnection startWithGraphPath:#"me/feed"
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];
}
m_postingInProgress = NO;
}];
}
the easiest way of sharing something from your iOS app is using the UIActivityViewController class, here you can find the documentation of the class and here a good example of use. It is as simple as:
NSString *textToShare = #”I just shared this from my App”;
UIImage *imageToShare = [UIImage imageNamed:#"Image.png"];
NSURL *urlToShare = [NSURL URLWithString:#"http://www.bronron.com"];
NSArray *activityItems = #[textToShare, imageToShare, urlToShare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityVC animated:TRUE completion:nil];
This will only work on iOS 6 and it makes use of the Facebook account configured in the user settings, and the Facebook SDK is not needed.
You can use Graph API as well.
After all the basic steps to create facebook app with iOS, you can start to enjoy the functionality of Graph API. The code below will post "hello world!" on your wall:
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
...
//to get the permission
//https://developers.facebook.com/docs/facebook-login/ios/permissions
if ([[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"]) {
NSLog(#"publish_actions is already granted.");
} else {
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithPublishPermissions:#[#"publish_actions"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
//TODO: process error or result.
}];
}
if ([[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"]) {
[[[FBSDKGraphRequest alloc]
initWithGraphPath:#"me/feed"
parameters: #{ #"message" : #"hello world!"}
HTTPMethod:#"POST"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(#"Post id:%#", result[#"id"]);
}
}];
}
...
The basic staff is presented here: https://developers.facebook.com/docs/ios/graph
The explorer to play around is here:
https://developers.facebook.com/tools/explorer
A good intro about it: https://www.youtube.com/watch?v=WteK95AppF4

Post to Facebook Friend's Wall in iPhone using New Facebook SDK

I want to post some texts and photo to one of my friend's wall using FBDialog.
I have a method like this
- (void)apiDialogFeedFriend:(NSString *)friendID :(NSString *)mImageSTR{
currentAPICall = kDialogFeedFriend;
FBSBJSON *jsonWriter = [FBSBJSON new];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
friendID, #"to",
#"I'm using the Hackbook for iOS app", #"name",
#"Hackbook for iOS.", #"caption",
#"Check out Hackbook for iOS to learn how you can make your iOS apps social using Facebook Platform.", #"description",
#"http://m.facebook.com/apps/hackbookios/", #"link",
#"http://www.facebookmobileweb.com/hackbook/img/facebook_icon_large.png", #"picture",
actionLinksStr, #"actions",
nil];
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[[delegate facebook] dialog:#"feed"
andParams:params
andDelegate:self];
}
Through these i get call back to dialogCompleteWithUrl method of FBDialogDelegate.
I have implemented this delegate method like this :
- (void)dialogCompleteWithUrl:(NSURL *)url {
if (![url query]) {
return;
}
NSDictionary *params = [self parseURLParams:[url query]];
switch (currentAPICall) {
case kDialogFeedUser:
case kDialogFeedFriend:
{
// Successful posts return a post_id
if ([params valueForKey:#"post_id"]) {
[self showMessage:#"Published feed successfully."];
NSLog(#"Feed post ID: %#", [params valueForKey:#"post_id"]);
}
break;
}
case kDialogRequestsSendToMany:
case kDialogRequestsSendToSelect:
case kDialogRequestsSendToTarget:
{
// Successful requests return the id of the request
// and ids of recipients.
NSMutableArray *recipientIDs = [[NSMutableArray alloc] init];
for (NSString *paramKey in params) {
if ([paramKey hasPrefix:#"to["]) {
[recipientIDs addObject:[params objectForKey:paramKey]];
}
}
if ([params objectForKey:#"request"]){
NSLog(#"Request ID: %#", [params objectForKey:#"request"]);
}
if ([recipientIDs count] > 0) {
[self showMessage:#"Sent request successfully."];
NSLog(#"Recipient ID(s): %#", recipientIDs);
}
break;
}
default:
break;
}
}
Here I get correct value of url as fbconnect://success?post_id=100001402819851_418640698226650.
Now, my problem is that in my friend wall my post is not seen/visible.
Any help would be appreciated.

How to check if a user has granted a certain permission Facebook iOS

In my iOS app, I just want to check if the user has granted the Facebook publish_stream permission.
I'm not sure how to handle the response to the call
[facebook requestWithGraphPath:#"me/permissions" andDelegate:self];
in my FBRequest delegate method. I've tried:
if (request == self.permissionRequest) {
NSString *key = [result objectForKey:#"publish_stream"];
DLog(#"Key: %#", key);
}
But I get null.
And if I try
id *key = [result objectForKey:#"publish_stream"];
int keyInt = [key integerValue];
DLog(#"Key: %i", keyInt);
I always get 0. Even when I know the permission is active...
You can make an FBRequest with the open graph API with "me/permissions".
It will return you a response with a dictionary where the key are the permissions. a value will be associated (1 = YES, 0 = NO)
Here's a working sample I did for create_events. Sure it could be used for others:
FBRequest *eventPostOK = [FBRequest requestWithGraphPath:#"me/permissions" parameters:Nil HTTPMethod:#"GET"];
[eventPostOK startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
BOOL canDoIt = FALSE;
if (!error)
{
FBGraphObject *data = [result objectForKey:#"data"];
for(NSDictionary<FBGraphObject> *aKey in data) {
canDoIt = [[aKey objectForKey:#"create_event"] boolValue];
}
}
else
NSLog(#"%#", error);
NSLog(#"%#", canDoIt ? #"I can create Events" : #"I can't create Events");
}];

Facebook Graph API for iOS search

I am trying to search places from the GraphAPI using following code without luck. Can anybody please enlight my path ?
If I try to post link/message/photo it works as expected but when trying to get location it always fails and gives me **The operation couldn’t be completed. (facebookErrDomain error 10000.)**
//Following statement is using permissions
NSArray * permissions = [NSArray arrayWithObjects:#"publish_stream",#"user_checkins", #"friends_checkins", #"publish_checkins", nil];
[facebook authorize:FB_APP_ID permissions:permissions delegate:_delegate];
NSString *centerString = [NSString stringWithFormat: #"%f,%f", 37.76,-122.427];
NSString *graphPath = #"search";
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"coffee",#"q",
#"place",#"type",
centerString,#"center",
#"1000",#"distance", // In Meters (1000m = 0.62mi)
nil];
[facebook requestWithGraphPath:_path andParams:_params andHttpMethod:#"POST" andDelegate:_delegate];
Never mind. Downloaded latest sample HackBook from facebook for graph api from github and it includes sample code for the same.
For "search" you should use "GET" instead of "POST".
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#search
With Facebook iOS SDK, you can use FBRequestConnection after login.
[FBRequestConnection startWithGraphPath:#"search?q=coffee&type=place&center=37.76,-122.427&distance=1000"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Sucess! Include your code to handle the results here
NSLog(#"result: %#", result);
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"error: %#", error);
}
}];
With Last SDK
NSMutableDictionary *params2 = [NSMutableDictionary dictionaryWithCapacity:3L];
[params2 setObject:#"37.416382,-122.152659" forKey:#"center"];
[params2 setObject:#"place" forKey:#"type"];
[params2 setObject:#"1000" forKey:#"distance"];
[[[FBSDKGraphRequest alloc] initWithGraphPath:#"/search" parameters:params2 HTTPMethod:#"GET"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
NSLog(#"RESPONSE!!! /search");
NSLog(#"result %#",result);
NSLog(#"error %#",error);
}];