HTTP status code 400 when posting to facebook FBiOSSDK.3.0.8 - ios

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

Related

How I can add summary to this Facebook Request?

I'm getting photo likes with this request, but I want to add the summary which returns to me the total likes count:
NSString *path=[NSString stringWithFormat:#"/%#/likes",IdPhoto];
[FBRequestConnection startWithGraphPath:path
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
}];
How can I add it?
Try with this call:
"/%#/likes?summary=true"
Source: https://developers.facebook.com/docs/graph-api/reference/v2.3/object/likes#read

Post on Facebook page as admin iOS Facebook SDK

I need to make a post on a my own fanpage as the admin.
I created this code hopping that passing the id of the page "fbPageID" would leave the post on that page, but it actually leaves the post on my profile.
NSArray *publishPerms = #[#"manage_pages",#"publish_actions", #"publish_stream"];
[FBSession openActiveSessionWithPublishPermissions:publishPerms defaultAudience:FBSessionDefaultAudienceEveryone allowLoginUI:NO completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (session.isOpen) {
[FBRequestConnection startForPostStatusUpdate:self.textBox.text place:fbPageID tags:nil completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error){
NSLog(#"error %#",error);
}
else{
NSLog(#"POSTED %#",result);
}
}];
}
else{
NSLog(#"session not open");
}
This is helpfull for Post on user Facebook..
Step 1 - Import FBSDK in your project
Step 2 - Login Authentication
NSDictionary *params = #{
#"message": #"This is a test message",
};
/* make the API call */
FBSDKGraphRequest *request_ = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"/me/feed"
parameters:params
HTTPMethod:#"POST"];
[request_ startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
// Handle the result
}];

iOS Facebook Api, make a like to a comment post

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.

iOS Facebook SDK get profile cover image

How can i get the cover of a profile with the FacebookSDK in iOS?
[FBRequestConnection startWithGraphPath:#"/me/events?fields=cover"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
/* handle the result */
NSLog(#"%#", result);
}];
you can also get facebook cover pic by simply calling
http://graph.facebook.com/{user_id or page_id}?fields=cover

Facebook iOS sdk to take user id

a question about Facebook sdk for iOS.
If I have an active session how can I get only the user ID?
Is there a simple way to obtain this id without use this example code?
if (FBSession.activeSession.isOpen) {
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *aUser, NSError *error) {
if (!error) {
// I can take the user id..
}
}];
}
+ (NSString *)activeUserId {
return [FBSDKAccessToken currentAccessToken].userID;
}
if you are already logged in on facebook.
This is best way to take user id, instead of directly access using dot.
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *aUser, NSError *error) {
if (!error) {
NSLog(#"User id %#",[aUser objectForKey:#"id"]);
}
}];
[FBRequestConnection startWithGraphPath:#"/me"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
NSDictionary *result,
NSError *error
) {
/* handle the result */
_fbId = [result objectForKey:#"id"];
}];

Resources