I want to like a comment of a post on Facebook, I use the same as like the post. For like a post, it works, but for like a comment fail.
Doc:
https://developers.facebook.com/docs/graph-api/reference/object/likes
My Code:
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:#"/%#/likes", postId_]
parameters:nil
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{ //Error:
}];
The Error is:
Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x158999b0 {com.facebook.sdk:HTTPStatusCode=400, com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 100;
message = "(#100) Error finding the requested story";
type = OAuthException;
};
};
code = 400;
}, com.facebook.sdk:ErrorSessionKey=}
Here is how I do it, and it works like a charm
// post is my module object, encapsulates the info form the post
// pass the post ID
NSString *graphPath = [NSString stringWithFormat:#"%#/likes", post.postID];
FBRequest *request = [FBRequest requestForGraphPath:graphPath];
// DELETE or POST the like
NSString *method = post.liked?#"DELETE":#"POST";
[request setHTTPMethod:method];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
BOOL success = YES;
success = (error)?NO:YES;
if(success) {
}
}];
Note: make sure you have publish permissions
In my project I use the following code:
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:URL, #"object", nil];
if (FBSession.activeSession.isOpen) {
if (FBSession.activeSession.accessTokenData.accessToken) {
[FBRequestConnection startWithGraphPath:#"/me/og.likes"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(#"Just liked on Facebook!");
}];
} else NSLog(#"Cannot open FBSession");
}
There no code for opening or initializing FBSession - I hope, it's not a problem?
I think, we all can trust Facebook, yes? :)
Go to https://developers.facebook.com/docs/reference/opengraph/action-type/og.likes, select "IOS SDK" tab and look at the code.
Related
I have written following code to post on facebook page but getting this error message: “(#200) Unpublished posts must be posted to a page as the page itself.“;
NSString *accesstoken = #"EAACEdEose0cBAAe49xNZBS5MqswXkRptXgLDRuZBZBPZCZCVl5rxW6Bt0jthaHXMACNTiUWePg9XkVTpttDNsLyWYBaEkQaUCm5vbSJQh8zGwkegAcQRjRggAJajunmMyg0jVIKZAZBzMjbZCKWUv1Tie1UzF8gJCpIxACIVgqx7SqKdPZBnIUaElk3meB7SYo6AZD";
NSString *pageId = [dic valueForKey:#"id"];
NSDictionary *dicPara=#{#"message": #"Hello",#"access_token":accesstoken,#"scheduled_publish_time": [NSNumber numberWithInt:timestamp],#"published": #"false"};
NSLog(#"%#",dicPara);
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:[NSString stringWithFormat:#"/%#/feed",pageId]
parameters:dicPara
HTTPMethod:#"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
// Insert your code here
if (error)
{
NSLog(#"%#",error);
}
else
{
[arrPostId addObject:[result valueForKey:#"id"]];
}
}];
Now I have searched for this error and found that you have to set accesstoken of the page instead of user's token. So how can I change user's access token to page accesstoken?
I'm using Facebook SDK v4 to get all the posts of a friend. I use the following code
FBSDKLoginManager* loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithReadPermissions:#[#"user_posts"] handler:^(FBSDKLoginManagerLoginResult *result, NSError* error) {
if (error) {
// Process error
NSLog(#"");
} else if (result.isCancelled) {
// Handle cancellations
NSLog(#"");
} else {
// If you ask for multiple permissions at once, you
// should check if specific permissions missing
if ([result.grantedPermissions containsObject:#"user_posts"]) {
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"/10002434324342/posts"
parameters:nil
HTTPMethod:#"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
// Handle the result
if (error) {
NSLog(#"");
}
}];
}
}
}];
10002434324342 is an example of facebookID. It just return an empty data list.
Can anyone tell me how to do this
Friend permissions have been removed with v2.0, you can only get data of users who authorized your App too, with the correct permissions. user_posts should always be used with /me/posts.
More information: https://developers.facebook.com/docs/apps/changelog
You can try
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"/{user-id-a}/friends/{user-id-b}"
parameters:params
HTTPMethod:#"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
// Handle the result
}];
https://developers.facebook.com/docs/graph-api/reference/v2.3/user/friends
I have been working with the facebook sdk and parse and I am trying to retrieve a users facebook name but the documentation doesn't give me sufficient help and most tutorials on the net are out dated.
Can anyone tell how I can get a users name from the facebook sdk to display as a text label ? This would be greatly appreciated thanks.
You need to implement following FBLoginViewDelegate
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user
{
NSLog(#"user is %# %#", [user objectForKey:#"email"], user.name);
}
You can retrieve it in this way:
FBRequest *request = [[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:#"me"];
[request startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary < FBGraphUser > *my,
NSError *error)
{
NSString *username = my[#"username"];
}
I finally figured it out, you have to request the current users profile information than set your label with a "key" which in this case is called "name"
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:#"me"
parameters:nil];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
NSLog(#"fetched user:%#", result);
_usernameText.text = result[#"name"];
}];
I am trying to post a link formatted as a string on facebook. Please see the relevant code below:
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
NSString *modifiedTitle = [NSString stringWithFormat:#"<a href= https://www.google.com> My App </a>"];
[params setObject:modifiedTitle forKey:#"message"];
[params setObject:UIImagePNGRepresentation(picture) forKey:#"picture"];
[FBRequestConnection startWithGraphPath:#"me/photos"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
if (error)
{
//showing an alert for failure
NSLog(#"ERROR in posting image to Facebook");
}
else
{
//showing an alert for success
NSLog(#"Result after posting image successfully = %#",result);
}
// button.enabled = YES;
}];
The message appeared as:
<a href= https://www.google.com> My App </a>
instead of
My App
For one thing, ensure you're posting an immmutable dictionary into the startWithGraph... method by using the copy method:
NSDictionary* paramsImmutable = params.copy;
[FBRequestConnection startWithGraphPath:#"me/photos"
parameters:paramsImmutable
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
That way you won't have any changes to worry about on that object during the method's lifetime.
Next, is your params including any sort of quotes around the url? I.e.
NSString *modifiedTitle = #"<a href='https://www.google.com'>My App</a>";
That's just a start.
i am using the ios sdk 3.0 to post simple text to user facebook wall , below is the code is use to post to facebook
[FBRequestConnection
startForPostStatusUpdate:text completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
if (!error)
{
NSLog(#"the status posted");
}
}];
but i get the error from facebook like
FBSDKLog: Response <#1115> :
The operation couldn’t be completed. (com.facebook.sdk error 5.) . any help would be appreciated.
The bug is if you try to share an NSString.
This works:
[FBRequestConnection startForPostStatusUpdate:#"test"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
}];
This gives you the error:
NSString *testString = #"test";
[FBRequestConnection startForPostStatusUpdate:testString
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
}];