Post on Facebook Page from iOS App Not Showing Up on Page? - facebook

I am posting a picture and dummy text on a facebook page with the Page Id "848190045198980".I am signing in using my facebook credentials.Also I have admin role for the specific page.So I am just getting the basic permissions from facebook.Below is the request and the response.
Request :
UIImage * productImage = [UIImage imageNamed:#"corporate.png"];
NSData * imageData = UIImagePNGRepresentation(productImage);
NSDictionary *params = #{#"message": #"Hello XYZ", #"source":imageData};
[FBRequestConnection startWithGraphPath:#"/848190045198980/photos" parameters:params HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error)
{
if(completionBlock)
{
NSLog(#"%#",result);
completionBlock(YES,result,nil);
}
}
else
{
if(completionBlock)
completionBlock(NO,nil,error);
}
}];
Response :
{"id":"1481175438805031","post_id":"848190045198980_1481175438805031"}
Expected Result : My Post should show up on the Facebook Page in "Posts to Page" Section.
Actual Result : Nothing Shows Up.
Please point me in the right direction as to what I am missing here.I have checked the API Doc several times and I am finding it real tough as to where I am missing something.
Regards,
Roman

This is how I am posting video on Facebook:
NSDictionary *params = #{
#"message":message,
#"tags":Mystring,
#"link":#"http://www.miimobileapp.com/website/index.html",
#"privacy": #"{'value': 'SELF'}",
};
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"/me/feed"
parameters:params
HTTPMethod:#"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,id result,NSError *error) {
NSLog(#"Post successful");
}

Related

Get FaceBook Friends List error code = 100 "Invalid username. field"

I am using PARSE integration for facebook. I am able to successfully link the user to facebook but when i try to get facebook firiends list i get the following error.
FBRequest *request = [FBRequest requestForMyFriends];
// Send request to Facebook
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
}];
error code = 100
message = "(#100) Unknown fields: username."
type = OAuthException
desperately need help!!
The field username is no longer available with the Graph API v2.0, see https://developers.facebook.com/docs/apps/changelog#v2_0_graph_api
Endpoints no longer available in v2.0:
...
/me/username is no longer available.
-(IBAction)btnFacebookClick:(id)sender
{
NSArray *permissions = [[NSArray alloc] initWithObjects: #"user_about_me,user_birthday,user_hometown,user_location,email",#"read_mailbox",#"read_stream",nil];
[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES completionHandler:^(FBSession *session,FBSessionState status,NSError *error)
{
if(error)
{
NSLog(#"session error %#",error);
}
else if(FB_ISSESSIONOPENWITHSTATE(status))
{
[self getFriendList];
}
}];
}
-(void)getFriendList
{
FBRequest *friendsRequest=[FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler:^(FBRequestConnection *connection,NSDictionary* result,NSError *error)
{
friendsArr = [result objectForKey:#"data"];
NSLog(#"friends description :%#",[friendsArr description]);
}];
}

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];
}
}}];

FBRequest get parameters issue

I want to get in my app info about the user. His name, age, location, gender, profile image and other stuff.
For now i am using :
-(void)facebookOpenSession{
FBRequest *me = [FBRequest requestForMe];
[me startWithCompletionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
NSDictionary *resultDic = (NSDictionary<FBGraphUser> *) result;
facebookData = [[NSMutableDictionary alloc]initWithDictionary:resultDic];
FBRequest *pic = [FBRequest requestForGraphPath:#"me/?fields=picture"];
[pic startWithCompletionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
NSDictionary *resultDic = (NSDictionary<FBGraphUser> *) result;
NSDictionary *dic = [resultDic objectForKey:#"picture"];
NSDictionary *dic2 = [dic objectForKey:#"data"];
NSString *imgUrl = [dic2 objectForKey:#"url"];
NSLog(imgUrl);
}];
}];
}
I made two requests ine for the user profile and one other for the image, and i want to know if i can make only one call? and if i want to get another info what i need to do?
The way you annotated your code is a little weird to read for me, so I re-wrote it like so:
if (FBSession.activeSession.isOpen) {
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {
self.nameString = user.name;
self.profileImage.profileID = user.id;
self.userName = user.username;
}
}];
}
It really isn't much more complicated than how I wrote it.
Happy Coding!
Addition to code due to comments:
You need to get the output from Facebook. For an image, your code should look like:
FBProfilePictureView *profileImage.profileID = user.id;
user.id comes from Facebook once you initiate an FBRequest.
You don't really convert the FBProfilePictureView into a UIImageView, but instead, set the FBProfilePictureView as a subview of a UIView that you create.
Also, you need to set the picture cropping:
profileImage.pictureCropping = FBProfilePictureCroppingSquare;
FBProfilePictureCroppingSquare is one of a few choices that you have. Read up on the documentation in Facebook Developer to see your options.

Facebook iOS SDK 3.0: how to make comment to existing URL?

Has anyone tried to use the new Facebook SDK to post a comment to an URL? i tried by using startForPostWithGraphPath like this (code snippet picked from Scrumptious project):
id action = [FBGraphObject graphObject];
[action setValue:#"test from iOS app" forKey:#"message"];
// Create the request and post the action to my url path.
[FBRequestConnection startForPostWithGraphPath:#"XXXXXXXXXXXXXXXXXXX/comments"
graphObject:action
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error)
{
NSLog(#"error: %#", error.localizedDescription);
}
else
{
NSLog(#"ok!!");
}
}];
it doesn't work neither from Open Graph API explorer. The error i receive is "an unknown error has occurred", code 200. The XXXXXXXX url is the ID of the page i have comments on, i can read them, but not correctly post to them. Maybe the open graph path is wrong?
Hey Friend It's a Good News for you.
I Post the comments and Likes with GraphAPI in IOS
Just write Some code below.
NSMutableDictionary *res = [NSMutableDictionary dictionaryWithObjectsAndKeys:#"This is my comment", #"message", #"Your api's access Token",#"access_token",nil];
[FBRequestConnection startWithGraphPath:#"XXXXXXXXXX/comments" parameters:res HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error)
{
NSLog(#"error: %#", error.localizedDescription);
}
else
{
NSLog(#"ok!!");
}
}];
XXXXXXXXXX = Id where you want to comment.
Note:-
Please do not appent https://graph.facebook.com
before
XXXXXXXXXX/comments

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);
}];