How to post comment on photo using graph api in iphone? - iphone

I have the following code:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:txtComment.text, #"message", nil];
NSString *strPicId = [[Appdel.arrFacebookImages objectAtIndex:Appdel.getIndex] valueForKey:#"id"];
NSString *strPath =[NSString stringWithFormat:#"%#/comments",strPicId];
[FBRequestConnection startWithGraphPath:strPath parameters:params HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result1, NSError *error)
{
if(!error)
{
}
else
{
NSLog(#"ERROR:%#",error);
}
}];
but when it runs, it giving me error like below,
ERROR:Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0xb36dd80 {com.facebook.sdk:HTTPStatusCode=403, com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 200;
message = "(#200) Requires extended permission: publish_stream";
type = OAuthException;
};
};
I have successfully logged in and I am also getting photo albums, photos, comments, but I can't post any comment on any photo.

It looks like you are missing publish permission in your access token.
You can get it with:
[FBSession openActiveSessionWithPublishPermissions:#[#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
if (FBSession.activeSession.isOpen && !error) {
// Publish the comment (your code inside) if permission was granted
[self publishComment];
}
}];
That was the code from: https://developers.facebook.com/docs/ios/publish-to-feed-ios-sdk/

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

ERROR (com.facebook.sdk error 5.) in ios

In my project i am not posting anything only fetching different data from FaceBook.
some times i am getting the data but
most of the time i am getting this Error
The operation couldn’t be completed. (com.facebook.sdk error 5.)
my small code is
permissions = [[NSArray alloc] initWithObjects:#"user_friends",#"read_stream",
#"read_requests",#"user_birthday",#"user_about_me",#"user_hometown",
#"user_location",#"user_likes",#"email",
nil];
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error) {
NSString *queryNew55 = #"SELECT post_id,fromid,time FROM comment WHERE time > 1375553100 AND post_id IN (SELECT post_id FROM stream WHERE source_id = me())";
// Set up the query parameter
NSDictionary *queryParam15 = #{ #"q": queryNew55 };
// Make the API request that uses FQL
[FBRequestConnection startWithGraphPath:#"/fql"
parameters:queryParam15
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error) {
NSLog(#"Error in comment query");
NSLog(#"Error: %#", [error localizedDescription]);
} else {
NSLog(#"comments Result: %#", result);
}
}
];
}];
I seen lots of thing on google on the same Error
and i applied that too but nothings works permanently.
in FaceBook App All the things like sandbox mode is off and bundle id are set perfectly.
any help like link or code or any thing related to this will be great Help.
I know this question is old, but my answer might help some other people.
I was getting this error after following some of their code/tutorials/documentation.
It seems there is a disconnect between their documentation and some of the sample code.
using
if (FBSession.activeSession.state != FBSessionStateCreated) {
// Create a new, logged out session.
self.facebookSession = [[FBSession alloc] init];
}
and
[self.facebookSession openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
will not result in the session being updated in
FBSession.activeSession
getting updated.
So you will have a session that is open (self.facebookSession) and a session that is crated&TokenLoaded - which is not open.
So making any calls like:
[FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
will fail as the FBRequestConnection uses FBSession.activeSession
So in the completion handler you can see the active session if you are going to manage the session your self.
[self.facebookSession openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
[FBSession setActiveSession:session];
// post or load user data.
}];
It seems to work for me now,
hope this helps

What is correct iOS syntax to create a Facebook event then send an invite to a user?

I have a session type called FBSession. I know the session is open, but how do I go about sending a graph request to create an event, then invite a user to that event? I know the users' Facebook IDs, as I managed to pull them from the local addressbook properties.
if (appDelegate.session.state == FBSessionStateCreatedTokenLoaded) {
// even though we had a cached token, we need to login to make the session usable
[appDelegate.session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
switch (status) {
case FBSessionStateOpen:
{
/* What do I do here to create the event and invite IDs x, y and z where z, y and z are long long Facebook Ids */
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"venue name",#"name",
#"2012-01-13T17:00:00+0000",#"start_time",
#"2012-01-16T01:30:00+0000",#"end_time",#"location",#"location name ch",#"1234567890",#"id", nil];
FBRequest *facebook = [[FBRequest alloc] initWithSession:appDelegate.session graphPath:#"me/events" parameters:params HTTPMethod:#"POST"];
Is any of this correct, and which delegate methods am I required to run to check if it worked OK back in the appDelegate?
OK did this seems cool.
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];
}
}
if (canDoIt) { ... DO STUFF .... }
];

FQL query with v3.1 Facebook SDK for iOS to get birthday and email

Can anyone help me. I cannot figure out how to make a single FQL query using the latest Facebook SDK (v 3.1) for iOS to get birthday and email of user's friend. When I query for fields like name i get the correct value but get null for email and birthday field.
Here is my code
- (void)facebookViewControllerDoneWasPressed:(id)sender {
// we pick up the users from the selection, and create a string that we use to update the text view
// at the bottom of the display; note that self.selection is a property inherited from our base class
for (id<FBGraphUser> user in _friendPickerController.selection) {
_nameTxt.text = user.name;
NSString *fql = [NSString stringWithFormat:#"SELECT email, birthday, name FROM user WHERE uid = %# ",user.id];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObject:fql forKey:#"q"];
[FBRequestConnection startWithGraphPath:#"/fql"
parameters:params
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error) {
NSLog(#"Error: %#", [error localizedDescription]);
} else {
NSLog(#"Result: %#", result);
}
}];
}
[self.navigationController dismissModalViewControllerAnimated:YES];
}
I'm getting value for name but null for email and birthday.
Thanks
Before you call your query, you'll need to have the user log in and ask for email and user_birthday permissions. For example:
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"email",
#"user_birthday",
nil];
return [FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];
}
The above method is used in the context of this tutorial:
https://developers.facebook.com/docs/howtos/login-with-facebook-using-ios-sdk/
Also check out the FQL tutorial:
https://developers.facebook.com/docs/howtos/run-fql-queries-ios-sdk/

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