I am using the newest facebook SDK 3.8 for iOS. I want to post a comment to a wall post and I am having troubles. The following method I am using works maybe once or twice and then gives me the error:
Error: The operation couldn’t be completed. (com.facebook.sdk error 5.)
I am not sure if it has to do with "overdoing" posting because I am only posting twice when this happens and on different posts each time. Like I said, it happens out of no where (Everytime before it is a success). So I believe it is my code. Can anyone tell me if I am doing this right?
Thank you!
-(BOOL) postComment: (NSString *) postID :(NSString *) userPostMessage;
{
__block BOOL value;
postID=[NSString stringWithFormat:#"/%#/comments?message=%#",postID,userPostMessage];
[FBSession activeSession];
[FBRequestConnection startWithGraphPath:postID parameters:0 HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
BOOL temp;
if (error)
{
NSLog(#"Error: %#", [error localizedDescription]);
temp = TRUE;
}
else
{
NSLog(#"Result: %#", result);
valueReturned = (NSString*)result;
temp = FALSE;
}
value = temp;
}];
return value;
}
Related
I am trying to retrieve list of FB friends which use the app. It was working fine until last month. I just realized that it is not working any longer. I am using the following block to achieve the results:
[FBRequestConnection startForMyFriendsWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
}
else
{
NSLog(#"%#",error)
}
}];
But quite contrary to previous results, Now I get the following error:
Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x174278280 {com.facebook.sdk:HTTPStatusCode=400, com.facebook.sdk:ErrorSessionKey=<PFReceptionist: 0x174026dc0>, com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 100;
message = "(#100) Unknown fields: username.";
type = OAuthException;
};
};
code = 400;
}}
Has the facebook sdk changed lately? It might be so because I can't get the gender and date of birth too now, which I was able to retrieve before. What do you reckon is the issue? How can I retrieve the friends who are using my app, as it is quite crucial for my app?
I fixed it using this block instead.
FBRequest *friendsRequest = [FBRequest requestForGraphPath:#"/me/friends"];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,NSDictionary* result,NSError *error) {
if(error)
{
NSLog(#"%#", error);
}
else
{
NSLog(#"%#", result);
}
}];
I m using Facebook SDK v3.11.1.
In my app, after i open a session, i look for some information view FQL query:
[FBRequestConnection startWithGraphPath:#"/fql"
parameters:#"SELECT uid, name, can_post FROM user WHERE uid = me()"
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error) {
NSLog(#"Error: %#", [error localizedDescription]);
} else {
NSString* resultString = [NSString stringWithFormat:#"NativeBridge.resultForCallback(mycallback, '%#');", result];
[self.myWebView stringByEvaluatingJavaScriptFromString:resultString];
}
}];
}
I try to invoke javaScript method in my UIWebView.
The object NativeBridge and the method resultForCallback are fine (checked in chrome devTool).
My problem is the parameter result which is actually FBGraphObject.
I try to send to javaScript parameter like:
{
data = (
{
"can_post" = 1;
name = "firstName lastName";
uid = 000000000000000;
}
);
}
But the javascript refuse to get this parameter.
Any help will be great!
Thanks in advance.
I'm developing a simple app that has a feature to compose user pictures and post them as a OG Story to facebook.
I followed the Facebook docs and I'm issuing the POST requests (I know I could batch them, I'm just trying to get any version working), I do get an story ID, but I can't find the story on Facebook. (permission set to friends)
I'm posting it with the path /me/:
When I check in the Graph Explorer this path returns an empty { 'data' : [] }
I know the story won't be posted on my profile, but I need to see it somewhere.
I need to test things such as deep linking (I know url is currently set to nil), but I can't find the story! The only place I could manage to see the picture is when I go to
developer page and click on 'preview'.
Any ideas?
Thanks in advance.
Here is the source code:
- (void) publishPhoto
{
// stage an image
[FBRequestConnection startForUploadStagingResourceWithImage:self.photo.image completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSLog(#"Successfuly staged image with staged URI: %#", [result objectForKey:#"uri"]);
// instantiate a Facebook Open Graph object
NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPostWithType:#"<APPNAMESPACE>:picture" title:#"" image:#[#{#"url":[result objectForKey:#"uri"], #"user_generated" : #"true"}] url:nil description:#""];
// Post custom object
[FBRequestConnection startForPostOpenGraphObject:object completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
// get the object ID for the Open Graph object that is now stored in the Object API
NSString *objectId = [result objectForKey:#"id"];
NSLog([NSString stringWithFormat:#"object id: %#", objectId]);
// create an Open Graph action
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:objectId forKey:#"picture"];
// create action referencing user owned object
[FBRequestConnection startForPostWithGraphPath:#"/me/<APPNAMESPACE>:take" graphObject:action completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSLog([NSString stringWithFormat:#"OG story posted, story id: %#", [result objectForKey:#"id"]]);
[[[UIAlertView alloc] initWithTitle:#"OG story posted"
message:#"Check your Facebook profile or activity log to see the story."
delegate:self
cancelButtonTitle:#"OK!"
otherButtonTitles:nil] show];
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"Encountered an error posting to Open Graph: %#", error.description);
}
}];
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"Encountered an error posting to Open Graph: %#", error.description);
}
}];
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"Error staging an image: %#", error.description);
}
}];
}
Try it with iPhone device instead of simulator. It'll work
I've integrated with Facebook so that I can, among other things, post statuses to my feed. I based some of my code off of the publish to feed developer tutorial. When running the following Graph API request from my iOS application the completion block of the request is never called and no error appears in the XCode debug log.
[FBRequestConnection
startWithGraphPath:#"me/feed"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error) {
DLog(#"error: domain = %#, code = %d", error.domain, error.code);
} else {
DLog(#"Posted action, id: %#", result[#"id"]);
}
}];
I have two convenience functions that perform checks against the current activeSession before executing this request. They look like this:
+ (BOOL)facebookSessionIsOpen {
return (FBSession.activeSession.isOpen);
}
+ (BOOL)facebookSessionHasPublishPermissions {
if ([FBSession.activeSession.permissions indexOfObject:#"publish_actions"] == NSNotFound ||
[FBSession.activeSession.permissions indexOfObject:#"publish_stream"] == NSNotFound ||
[FBSession.activeSession.permissions indexOfObject:#"manage_friendlists"] == NSNotFound) {
return NO;
} else {
return YES;
}
}
Both of these functions return YES indicating an active session with the necessary publishing permission. What's more confusing is that I can pull the user's profile without issue after performing the same checks successfully (granted publishing permissions are not required to pull the profile) using the following code:
[FBRequestConnection
startWithGraphPath:#"me"
parameters:[NSDictionary dictionaryWithObject:#"picture,id,birthday,email,location,hometown" forKey:#"fields"]
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSDictionary* resultDict = (NSDictionary*)result;
NSString* emailAddress = resultDict[#"email"];
NSString* location = resultDict[#"location"][#"name"];
NSString* birthday = resultDict[#"birthday"];
NSString* homeTown = resultDict[#"hometown"][#"name"];
...
}];
Any suggestions on how to debug this issue?
Turns out the issue was a threading one. The Facebook iOS SDK doesn't seem to like to execute a FBRequest on a different thread from the one that you called openActiveSessionWithReadPermissions on and promptly deadlocks. It turns out I was running the postStatus request in a separate thread like so:
dispatch_queue_t some_queue = dispatch_queue_create("some.queue.name", NULL);
dispatch_async(some_queue, ^{
[FacebookHelper postStatusToFacebookUserWall:newStatus withImage:imageData];
}];
Make sure your openActiveSessionWithReadPermissions and any FBRequest permutations all happen on the same thread, or you'll likely run into these silent failures.
I'm new to facebook SDK.
Last time I used facebook IOS SDK 3.0 and posting image through graph API. It is working but now it's not. I upgraded to 3.1 but still, it always return HTTP ERROR 200. Is there anyone can help me?
this is the code
- (void) facebookPostPhoto:(UIImage *)photo withMessage:(NSString *)msg withOkAction:(SEL)okAction andNGAction:(SEL)ngAction withTarget:(id)target {
ok = okAction;
ng = ngAction;
curView = target;
NSMutableDictionary *params;
params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
UIImageJPEGRepresentation(photo, 90), #"source",
msg, #"message",
nil];
if ([FBSession.activeSession.permissions indexOfObject:FacebookPermission_3] == NSNotFound) {
NSLog(#"permission not found");
// No permissions found in session, ask for it
[FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObjects:FacebookPermission_1, FacebookPermission_3, nil] defaultAudience:FBSessionDefaultAudienceFriends completionHandler:^(FBSession *session, NSError *error)
{
// If permissions granted, publish the story
if (!error) [self initPostFacebookWithParams:params];
}];
} else {
[self initPostFacebookWithParams:params];
} }
- (void)initPostFacebookWithParams:(NSMutableDictionary *)params {
[FBRequestConnection startWithGraphPath:#"me/photos" parameters:params HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(#"ERROR : %#", error.localizedDescription);
if (!error) {
NSLog(#"Facebook Post Success..");
if (ok && curView) {
[curView performSelector:ok];
}
} else {
NSLog(#"Facebook Post Failed..");
if (ng && curView) {
[curView performSelector:ng withObject:error];
}
}
}]; }
I appreciate your fast response and help! Thank You!!
I think it's either facebook upload's server is down or there is a new policy about image size. When I down sized the image to 320x320 it returns no error, sometimes error too by the way.
So for those who see this question, try to resize your image to smaller size.