简体   繁体   中英

Facebook API auto post on wall

I have a requirement where I need to publish some updates on users wall automatically. Users have already granted permission for publish_actions and I have USER IDs stored in DB. Now by using some cron jobs, I want to update those users wall either with some photos or with some links.

I tried this code:

<?php
    $config = array();
    $config['appId'] = 'XXX';
    $config['secret'] = 'XXX';
    $config['fileUpload'] = false; // optional

    $facebook = new Facebook($config);
    $session = $facebook->getUser();
    $result = $facebook->api(array(
        'method' => 'users.setStatus',
        'status' => 'Hello World',
        'uid' => '123', /// user_id 
        'session' => $session,
            ));
?>

This works fine, but it is not sharing links as feed or photos. Using JS Sdk it was possible but it seems that FB has discontinued that since 6 Feb 2013.

Is there any correct way to do this?

Use Facebook 3.0 PHP-SDK , $facebook->api() first argument requires an endpoint /me/feed , /me/photos while the second is the method GET , POST and DELETE and the third is an array of parameters you want to send along with the call so try:

$session = $facebook->getUser();
if ($session) {

      $p = array( 'message'      => 'Hello World',
                  'access_token' => 'CAAA...' ); // a valid access token with publish_action permission
      $result = $facebook->api('/me/feed', 'POST', $p);

} else { 

      $loginUrl = $facebook->getLoginUrl();
      header('Location:'. $loginUrl);

}

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