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

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

Related

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

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

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

Tagging a friend to the wall post using graph API in iOS

I am using this code to post on my wall and at the same time I want to tag to my specefic friends but don't know how I am using Fbgrapgh API please help me.
[variables setObject:messageTextView.text forKey:#"message"];
[graphref doGraphPost:[NSString stringWithFormat:#"me/feed",self.friendID] withPostVars:variables];
Thanks
To tag someone you have to use FbDialogs. you cannot tag your friends in status update in any way other than FB dialogs.
to share status using FBDialog refer this sample code
[FBDialogs presentShareDialogWithLink:nil handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];
it is taken from here https://developers.facebook.com/ios/share-dialog/#statusupdate

iPhone SDK: Tag friends in Post using Facebook Graph API

I try to post a status with friends tags using FBRequestConnection class method startForPostStatusUpdate:place:tags:completionHandler:
As
[self dismissViewControllerAnimated:YES completion:nil];
[FBRequestConnection startForPostStatusUpdate:Message
place:nil
tags:[NSArray arrayWithArray:users] completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
[self showAlert:#"" result:result error:error];
}];
Where users array contains user id's.
the error message i received "Cannot Specify user tags without place tag".
Please tell me solutions how can i add place parameters in this method.
[FBRequestConnection startForPostStatusUpdate:#"test message with place and tags" place:#"155021662189" tags:#[#"yourFriendID"] completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(#"startForPostStatusUpdate: %#, error: %#", result, error);
}];
Use 155021662189 as null value for place

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