Jonathan Eckman
Jonathan Eckman

Reputation: 2077

Facebook redirect_uri after post

I understand how to redirect a user after a logging in through facebook api, but how can I set the redirect destination for after a successful post. This is how I am simultaeously posting to facebook and my blog at the same time.

$post_url = '/'.$userPageId.'/links';

$msg_body = array(
  'message' => 'Hello World',
  'link' => 'http://localhost:8888/path/to/my/blog?blog='.$this->id,
);

$postResult = $facebook->api($post_url, 'post', $msg_body );

Currently, user will fill out the web form (new_blog.php) with the required blog fields, hit submit, and the blog will post to my websites database and also to facebook and then redirect back to new_blog.php. I need to redirect to a different page after successful post.

Upvotes: 1

Views: 492

Answers (1)

Sahil Mittal
Sahil Mittal

Reputation: 20753

All calls to the Facebook Graph API via the PHP SDK are synchronous. Therefore you can call any function directly after the call to the API, eg:

<?php
try 
{
    $result = $facebook->api($post_url, 'post', $msg_body);
    do_something($result);
} 
catch (Exception $e) 
{
  // Error
}
?>

Upvotes: 1

Related Questions