简体   繁体   中英

Posting image with caption with Facebook IOS SDK 3.1 and Graph API

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM