swifferina
swifferina

Reputation: 293

Facebook SDK for iOS doesn't post a photo along with the link

I'm trying to post a message including a link and an image, but on the post I can't see the image. I don't get error. The post is published correctly, displaying both the message and the link, but the photo does not show.

-(void)postOnFacebook
{
if (FBSession.activeSession.isOpen)
    [self postOnWall];
else
{
    [FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObjects:@"publish_actions", nil]
                                       defaultAudience:FBSessionDefaultAudienceEveryone
                                          allowLoginUI:YES
                                     completionHandler:^(FBSession *session,
                                                         FBSessionState status,
                                                         NSError *error)
     {
         if (error)
             NSLog(@"Login failed");
         else if (FB_ISSESSIONOPENWITHSTATE(status))
             [self postOnWall];
     }];
};
}

- (void)postOnWall
{
FBRequestConnection *newConnection = [[FBRequestConnection alloc] init];

FBRequestHandler handler =
^(FBRequestConnection *connection, id result, NSError *error) {
    [self requestCompleted:connection forFbID:@"me" result:result error:error];
};

NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                               @"Test", @"message",
                               @"www.google.com", @"link",
                               [UIImage imageNamed:@"temp.png"], @"picture",
                               @"description", @"description",
                               nil];

FBRequest *request=[[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:@"me/feed" parameters:params HTTPMethod:@"POST"];
[newConnection addRequest:request completionHandler:handler];
[requestConnection cancel];
requestConnection = newConnection;
[newConnection start];
 }

Upvotes: 0

Views: 151

Answers (2)

Sahil Mittal
Sahil Mittal

Reputation: 20753

The picture parameter expects a valid url. See here for more information.

If you have the picture data then you first have to deploy that and generate a link to that image and then provide the same to the picture url.

Or, you can first post a image on the facebook using /photos and then use that in the /feed.

Hope that helps. Good luck!

Upvotes: 1

HMHero
HMHero

Reputation: 2343

You should use graphPath:@"me/photos" instead of graphPath:@"me/feed" when you post a picture

Upvotes: 0

Related Questions