Постинг через Facebook API v3 (18.11.2014)
Использую старую версию Facebook PHP SDK (v.3.2.3), поскольку для четверки нужен имеющийся не везде PHP 5.4.
Авторизация:
<?
require 'facebook-php-sdk/src/facebook.php';

$facebook = new Facebook(array(
  'appId'  => '$appId',
  'secret' => '$secret',
));

// Get User ID
$user = $facebook->getUser();
Костыль со stackoverflow, перенаправляющий нас на авторизацию, если она не подхватилась:
if ($user <> '0' && $user <> '') { /*if valid user id i.e. neither 0 nor blank nor null*/
  try {
  // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) { /*sometimes it shows user id even if user in not logged in and it results in Oauth exception. In this case we will set it back to 0.*/
    error_log($e);
    $user = '0';
  }
}
else {/*If user id isn't present just redirect it to login url*/
  header("Location:{$facebook->getLoginUrl(array('req_perms' => 'email,offline_access'))}");
}
Попытаемся запостить сообщение на стену группы:
$facebook->api('/$group_id/feed/', 'post', array(
    'message' => 'I want to display this message on my wall',
  'link' => 'http://kodilo.ru',
  'picture' => 'http://images.boomsbeat.com/data/images/full/1893/facebook-jpg.jpg',
  'name' => 'The name of the link',
  'caption' => 'Caption of the link',
  'description' => 'Description of the link'
));
?>

Facebook PHP SDK
Решение проблемы с user=0
PHP, API
comments powered by Disqus
JavaScript (13)
PHP (11)
Brainfuck (8)
adm (8)
Joomla (4)
Canvas (3)
answers (2)
API (2)
CMS (2)
Modx (2)
jQuery (1)
Ajax (1)
SQL (1)
Shell (1)
batch (1)
10-6