How to post status feed on Facebook page as pageadmin in iOS? - ios

I want to post status on my Facebook page. Status should be shown on Facebook as a page status not status from any username or from my name.
I tried below code,
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:#"This is a check for page post message", #"message", nil];
/* make the API call */
[FBRequestConnection startWithGraphPath:#"/1521177224766299/feed"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error){
if (result)
{
NSLog(#"Result %#", result);
}
else
{
NSLog(#"%#", error);
}
}];
a message status was posted done page wall but that status come from my name.
But when I tried to hit same post method with page_id/feed POST Query and with same parameter #"this is my status" #"message" from graph api explorer page, it posted status from page not from me.
Please help.

NSString *accesstoken=[NSString stringWithFormat:#"%#","here add your page access_token"];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
accesstoken, #"access_token",
postingString, #"message",
// #"http://www.real-timesports.com", #"link",
nil];
FBRequest *requestToPost = [[FBRequest alloc] initWithSession:nil
graphPath:#"/me/feed"
parameters:params
HTTPMethod:#"POST"];
NSLog(#"requestToPost==%#",requestToPost);
FBRequestConnection *requestToPostConnection = [[FBRequestConnection alloc] init];
[requestToPostConnection addRequest:requestToPost completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
NSLog(#"facebook result >> %#", result);
}];
[requestToPostConnection start];

Here is Complete Answer
NSString *accesstoken = <Facebook_Page_Access_Token>
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
#"Post heading", #"name",
accesstoken, #"access_token",
#"Type post message", #"message",
#"Hyperlink to your post", #"link",
#"Add description", #"description",
#"Image url string", #"picture",
nil];
FBRequest *requestToPost = [[FBRequest alloc] initWithSession:nil
graphPath:#"/me/feed"
parameters:params
HTTPMethod:#"POST"];
FBRequestConnection *requestToPostConnection = [[FBRequestConnection alloc] init];
[requestToPostConnection addRequest:requestToPost completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
if (!error) {
NSLog(#" %#", result);
}
else
{
NSLog(#"%#", error);
}
}];

Related

How to post on Facebook page as Page Post from app via graph API in iOS?

I am trying to post on Facebook page as a page post. I using am below graph code API, but post coming on side as other people post, not as page admin/Page itself:
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
#"Testing Post", #"name",
#"This is testing", #"message",
#"this is description", #"description",
nil];
NSString *feed = [NSString stringWithFormat:#"/Page ID/feed"];
[FBRequestConnection startWithGraphPath:feed
parameters:params
HTTPMethod:#"POST"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
if(!error){
NSLog(#"%#", result);
}
else{
NSLog(#"Error %#", error);
}
}];
If you want to post as the Page itself, you'll need to use a Page Access Token with the publish_pages permission.
See
https://developers.facebook.com/docs/graph-api/reference/v2.3/page/feed#publish
https://developers.facebook.com/docs/facebook-login/access-tokens#pagetokens
Here is Complete Answer
NSString *accesstoken = <Page_Access_Token>
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
#"Post heading", #"name",
accesstoken, #"access_token",
#"Type post message", #"message",
#"Hyperlink to your post", #"link",
#"Add description", #"description",
#"Image url string", #"picture",
nil];
FBRequest *requestToPost = [[FBRequest alloc] initWithSession:nil
graphPath:#"/me/feed"
parameters:params
HTTPMethod:#"POST"];
FBRequestConnection *requestToPostConnection = [[FBRequestConnection alloc] init];
[requestToPostConnection addRequest:requestToPost completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
if (!error) {
NSLog(#" %#", result);
}
else
{
NSLog(#"%#", error);
}
}];

Building Facebook IOS friend multi-selector

I want to build a friend multiselector so that my user can send a request to anyone of his friends. I know that there is the FBfriendselectorcontroller, but it does not have the option to select all friends, and I would like to have it in my app. I tried to populate a UITableview manually by getting the friend list in this way:
permissions (logged in using the log-in button):
NSArray *permissions = [[NSArray alloc] initWithObjects:#"public_profile", #"email", #"user_friends", nil];
self.loginView.readPermissions = permissions;
data:
[FBRequestConnection startWithGraphPath:#"me/friends"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
//NSArray *data = [result objectForKey:#"data"];
NSLog(#"%#", result);
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys: [NSString stringWithFormat:#"%#", result], #"to", #"send", #"action_type", #"YOUR_OBJECT_ID", #"object_id", nil];
[FBWebDialogs
presentRequestsDialogModallyWithSession:nil
message:#"Take this bomb to blast your way to victory!"
title:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {}
];
}];
the friend count returns 318, but the "data" is like this: (). I also tried the:
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error){
NSArray* friends = [result objectForKey:#"data"];
but the data is null. What am I doing wrong??!!

Facebook SDK for iOS doesn't post a photo along with the link

I'm trying to post a message including a link and an image, but on the post I can't see the image. I don't get error.
The post is published correctly, displaying both the message and the link, but the photo does not show.
-(void)postOnFacebook
{
if (FBSession.activeSession.isOpen)
[self postOnWall];
else
{
[FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObjects:#"publish_actions", nil]
defaultAudience:FBSessionDefaultAudienceEveryone
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error)
{
if (error)
NSLog(#"Login failed");
else if (FB_ISSESSIONOPENWITHSTATE(status))
[self postOnWall];
}];
};
}
- (void)postOnWall
{
FBRequestConnection *newConnection = [[FBRequestConnection alloc] init];
FBRequestHandler handler =
^(FBRequestConnection *connection, id result, NSError *error) {
[self requestCompleted:connection forFbID:#"me" result:result error:error];
};
NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
#"Test", #"message",
#"www.google.com", #"link",
[UIImage imageNamed:#"temp.png"], #"picture",
#"description", #"description",
nil];
FBRequest *request=[[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:#"me/feed" parameters:params HTTPMethod:#"POST"];
[newConnection addRequest:request completionHandler:handler];
[requestConnection cancel];
requestConnection = newConnection;
[newConnection start];
}
The picture parameter expects a valid url. See here for more information.
If you have the picture data then you first have to deploy that and generate a link to that image and then provide the same to the picture url.
Or, you can first post a image on the facebook using /photos and then use that in the /feed.
Hope that helps. Good luck!
You should use graphPath:#"me/photos" instead of graphPath:#"me/feed" when you post a picture

Posting images & text to Timeline using Facebook SDK

Is it possible to use the Facebook SDK or Graph API to create a post like the one below?
I essentially want to combine these two together:
[FBRequestConnection startForUploadPhoto:[UIImage imageNamed:#"myImage"] completionHandler:nil];
[FBRequestConnection startForPostStatusUpdate:#"Hello, World!" completionHandler:nil];
Thanks.
Use following method :
// Present share dialog
[FBDialogs presentShareDialogWithLink:params.link
name:params.name
caption:params.caption
description:params.description
picture:params.picture
clientState:nil
handler:^(FBAppCall *call, NSDictionary *results, 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 {
// Success
NSLog(#"result %#", results);
}
}];
Here is the reference : https://developers.facebook.com/docs/ios/share
Try this,
FBRequestConnection *connection = [[FBRequestConnection alloc] init];
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[dictionary setObject:UIImagePNGRepresentation(_image) forKey:#"picture"];
if (message) {
[dictionary setObject:message forKey:#"message"];
}
FBRequest *request = [FBRequest requestWithGraphPath:#"me/photos" parameters:dictionary HTTPMethod:#"POST"];
[connection addRequest:request completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
}];
[connection start];

How to post image to friend's Facebook wall

NSData* imageData = UIImageJPEGRepresentation(self.qqqimage, 90);
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
self.messegeSend.text, #"message",
imageData, #"source",
nil];
postPath = [postPath stringByAppendingFormat:#"%#/feed",[friendList objectAtIndex:i]] ;
[FBRequestConnection startWithGraphPath:postPath
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
This is my code , but get error http 200
I also try postPath with #"%#/photos",friendID , but http 200 again

Resources