sharing text on "facebook Page" in ios from our app - iphone

I have a Facebook page, and i want to share some text on that page just like my status as we share on our "me/feed" from our application.
Please someone suggest how i should go about it?

for iOS 6.0 you can do something like that:
NSString *text1 = [NSString stringWithFormat:#"%# %#", NSLocalizedString(#"Check out this nice'... ", #""), self.title];
NSString *text2 = [NSString stringWithFormat:#"%# %#", NSLocalizedString(#"in", #""), self.restaurant.title];
NSString *text3 = NSLocalizedString(#"Sent from FoodRock Menus App", #"");
NSURL *appURL = [NSURL URLWithString:#"http://testappstorelink.com"];
NSArray *activityItems = [NSArray arrayWithObjects:text1, text2, text3, appURL, photo, nil];
UIActivityViewController *actVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems
applicationActivities:nil];
actVC.excludedActivityTypes = [NSArray arrayWithObjects:UIActivityTypeAssignToContact, UIActivityTypeCopyToPasteboard,
UIActivityTypePrint, UIActivityTypeSaveToCameraRoll, nil];
actVC.completionHandler = ^(NSString *activityType, BOOL completed){
DLog(#"ACTIVITYTYPE: %# FINISHED: %#", activityType, completed ? #"YES" : #"NO");
if (completed) {
NSString *socialString = #"";
if ([activityType containsSubstring:#"PostToTwitter"]) {
socialString = #"Twitter";
} else if ([activityType containsSubstring:#"PostToFacebook"]) {
socialString = #"Facebook";
} else if ([activityType containsSubstring:#"Message"]) {
socialString = #"Message";
} else if ([activityType containsSubstring:#"Mail"]) {
socialString = #"Mail";
}
[[FRNWAchievementsController controller] reportSocialShareEvent:socialString menuItem:self];
}
};
return actVC;

Here are some code snippets to help you out, but you should also have a look at the Facebook developer examples which are pretty good.
// To log in to Facebook with permission to post...
m_Facebook = [[Facebook alloc] initWithAppId:YOUR_FACEBOOK_APPID
andDelegate:self];
m_FacebookPermissions = [[NSArray
arrayWithObjects:/*#"read_stream",*/ #"publish_stream", nil] retain];
[m_Facebook authorize:m_FacebookPermissions];
And in some other method after the fbDidLogin callback tells you you're logged in:
// After successful login…
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
WHAT_YOU_WANT_TO_SAY, #"message",
nil];
[m_Facebook requestWithGraphPath:#"/me/feed"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];

Related

iOS Facebook SDK 3.2 Image Publish w/Description Open Graph

No matter what I try I cannot get my description to show up on Facebook. I used the debugger and all is well with the generated link and the URL is populated with the appropriate data. The picture is uploaded fine, but the description is not there. Is there something I need to setup in Facebook settings for the app?
Here is the relevant code:
- (id<FBPost>)outfitObjectForOutfit{
id<FBPost> result = (id<FBPost>)[FBGraphObject graphObject];
NSString *format =
#"http://mysite.mobi/app/fbOpen.php?"
#"og:title=%#&og:description=%%22%#%%22&"
#"og:caption=%%22%#%%22&"
#"og:image=http://mysite.mobi/images/transBlank.png&"
#"body=%#";
result.url = [NSString stringWithFormat:format,
#"New Post Title",fldDescription.text,fldDescription.text,fldDescription.text];
return result;
}
And the portion that publishes to FB:
- (void)postOpenGraphActionWithPhotoURL:(NSString*)photoURL
{
id<FBPost> outfitObject = [self outfitObjectForOutfit];
id<FBPostOutfit> action =
(id<FBPostOutfit>)[FBGraphObject graphObject];
action.outfit=outfitObject;
if (photoURL) {
NSMutableDictionary *image = [[NSMutableDictionary alloc] init];
[image setObject:photoURL forKey:#"url"];
NSMutableArray *images = [[NSMutableArray alloc] init];
[images addObject:image];
action.image = images;
}
[FBSettings setLoggingBehavior:[NSSet
setWithObjects:FBLoggingBehaviorFBRequests,
FBLoggingBehaviorFBURLConnections,
nil]];
NSLog(#"%#",action);
NSMutableDictionary *params = [NSMutableDictionary dictionary];
[params setObject:fldDescription.text forKey:#"message"];
[FBRequestConnection startForPostWithGraphPath:#"me/appnamespace:action"
graphObject:action
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];
NSLog(#"%#",error);
}
[[[UIAlertView alloc] initWithTitle:#"Result"
message:alertText
delegate:nil
cancelButtonTitle:#"Thanks!"
otherButtonTitles:nil]
show];
}
];
}
I figured out my problem. I was confusing what the Facebook examples did (activity publishing) with publishing to a user's wall. This was all that I had to do to get it to work:
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:fldDescription.text forKey:#"message"];
[params setObject:UIImagePNGRepresentation(userImage) forKey:#"picture"];
[FBRequestConnection startWithGraphPath:#"me/photos"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
if (error) {
[[[UIAlertView alloc] initWithTitle:#"Result"
message:#"Sorry there was an error posting to Facebook."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil]
show];
}
}];
I should also mention that I had to go into the opengraph settings for my app and allow user messages and user generated photos.

How to tag friends in your Facebook wall post...?

I am trying to tag some of my friends in my wall post and I am sending the following parameters but this posts to my wall the FB ids I provide do not get attached to the post...
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Test 2 ",#"message",
#"100004311843201 , 1039844409", #"to",
#"http://www.google.com", #"link",
#"Test", #"name",
nil];
[self.appDelegate.facebook requestWithGraphPath:#"me/feed" andParams:params andHttpMethod:#"POST" andDelegate:self];
Any help is appreciated...
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];
}
}

How to resolve property array not found on object of type "AppDelegate" error

I'm trying to post to a user's friend's FB wall with the following code. I'm stuck on this line: ** NSString *post=[[delegate.array objectAtIndex:tag.tag] objectForKey:#"id"];
**
with the error message: "property array not found on object of type "AppDelegate"
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
//Call the request method
[[delegate facebook] requestWithGraphPath:#"me/friends" andDelegate:self];
// get the array of friends
NSArray *data = [result objectForKey:#"data"];
// Check that the user has friends
if ([data count] > 0) {
NSMutableArray *array = [NSMutableArray array];
for (int i = 0; i < data.count; i++){
id object = [data objectAtIndex:i];
[array addObject:[object objectForKey:#"name"]];
}
NSLog(#"list of friends %#", array);
NSString *Message = [NSString stringWithFormat:#"-posted via iPhone App"];
NSMutableDictionary *params1 = [NSMutableDictionary dictionaryWithObjectsAndKeys:
Message, #"message", nil];
NSString *post=[[delegate.array objectAtIndex:tag.tag] objectForKey:#"id"];
[[delegate facebook] requestWithGraphPath:[NSString stringWithFormat:#"/%#/feed",post] andParams:params1 andHttpMethod:#"POST" andDelegate:self];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Message!" message:#"Message Sent" delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
[alert release];
Last 3 days i realize you got problem with get facebook friend in iphone. so i make a demo for you . hope you enjoy this.:)
Fetch Facebook friend here

How to post a photos on facebook through iPhone app?

I am trying to post image on facebook but not successful yet,
my codes are:
- (void)postToWall{
int im = 1;
NSData *myimgData;
myimgData = [NSData dataWithContentsOfFile:saveImagePath];
//pstimg = myimgData;
NSArray *chunks = [pstimg componentsSeparatedByString: #"."];
NSString *atch= [chunks objectAtIndex: 0];
NSString *filePath = [[NSBundle mainBundle] pathForResource:atch ofType:#"jpg"];
img = [[UIImage alloc] initWithContentsOfFile:filePath];
//start
FBDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
NSString *str = #"Hello";
str = [str stringByReplacingOccurrencesOfString:#" " withString:#"+"];
dialog.cMessage=str;
dialog.userMessagePrompt = #"Enter your message:";
[dialog show];
NSData * findata;
//edited from here
if(im==1)
{
findata = myimgData;
}
else
{
findata = (NSData *)img;
}
NSMutableDictionary * param = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img, #"picture",
nil];
FBRequest *uploadPhotoRequest =[FBRequest requestWithDelegate:self] ;
[uploadPhotoRequest call:#"facebook.photos.upload" params:param dataParam:myimgData];
[img release];
}
But it not posted.
To post a photo on Facebook you need to use the iOS SDK from Facebook:
https://github.com/facebook/facebook-ios-sdk
There you'll find sample app with authentication and much more, like posting a photo.

How to send text and images using Facebook API in iPhone SDK?

In my iPhone app, I want to send text as well as images to facebook.
Currently the facebook API suggest that there are seperate user permissions that enable us to do so.
Is there a way out where in I can do both using only one API in my project?
If Yes, How can we do so?
References to any articles or tutorials would be very helpful
Please Help & Suggest.
Thanks
Yes you can do this.
Please have a look at all the methods as below:
- (IBAction)uploadPhoto:(id)sender {
[self postOnFacebook];
}
//Post Message and Photo on Facebook Function
-(void)postOnFacebook
{
NSString *strPostMessage = [self createMessageForPostOnFacebook:74.112 withLongitude:21.85];
//UIImage *img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:objClsProductSearch.strProductImageURL]]];
//UIImage *img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://www.facebook.com/images/devsite/iphone_connect_btn.jpg"]]];
UIImage *img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://d1xzuxjlafny7l.cloudfront.net/wp-content/uploads/2011/08/HUDTutorial.jpg"]]];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
strPostMessage,#"message",img, #"source",
nil];
[_facebook requestWithGraphPath:#"/me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
[img release];
}
//Create Message for posting on Facebook
-(NSString *)createMessageForPostOnFacebook:(double)pfltLatitude withLongitude:(double)pfltLongitude
{
//NSString *urlString = [NSString stringWithFormat:#"http://maps.google.com/maps/geo?q=%f,%f&output=csv",pfltLatitude, pfltLongitude];
//NSString *urlString = [NSString stringWithFormat:#"http://maps.google.com/maps/geo?q=%f,%f&output=csv",#"", #""];
//NSError* error;
//NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSASCIIStringEncoding error:&error];
//NSArray *listItems = [locationString componentsSeparatedByString:#","];
NSString *strMessage = nil;
/*if([[listItems objectAtIndex:0] isEqualToString:#"200"])
{
strMessage = [NSString stringWithFormat:#"I found a %# using BH for iPhone \n Location : %# \n Latitude : %f & Longitude : %f \n Product Rating : %d",objClsProductSearch.strCategoryname,[locationString substringFromIndex:6],appDelegate.dblLatitude,appDelegate.dblLongitude,btnTmp.tag];
}*/
strMessage = [NSString stringWithFormat:#"I found a %# using BH for iPhone \n Location : %# \n Latitude : %f & Longitude : %f \n Product Rating : %d", #"Cat Name", #"Location", 74.112, 21.85, 1];
return strMessage;
}
I hope you will have success using the above code.
Let me know in case of any difficulty.
In you app delegate, have a look at below methods whether it is implemented or not.
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
//return [[controller facebook] handleOpenURL:url];
//return [[objPage2ViewController facebook] handleOpenURL:url];
return [[[self.navigationController topViewController] facebook] handleOpenURL:url];
}
Cheers
I'm not sure that it is possible. I've post image with next solution:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
takedPhoto, #"picture",
#"some text", #"message",
nil];
[facebook requestWithGraphPath:#"/me/photos" andParams:params
andHttpMethod:#"POST" andDelegate:self];
takedPhoto is UIImage.
But it is only loading photos in photo album (and approve it if you allow permissions when logging in).
I don't know how can I post message on wall with this uploaded image...
Regards,