0

After I was searching how to post data to facebook page, now I can do it well.

<?php
// Remember to copy files from the SDK's src/ directory to a
// directory in your application on the server, such as php-sdk/
require '../src/facebook.php';

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

$user_id = $facebook->getUser();                        
echo "User data ".$user_id." \n";

try {

if($user_id) {

    $ret_obj = $facebook->api('/microdigit.it/feed/', 'POST',
                                array(  
                                    //'access_token' => 'AAACEdEose0cBAExkj6B4lnjpUtfSSVTOZA9CuvMA1SDjyCQWRnfZCbc1SimyRsZCTa6CUFZB2Q3ZBfVIv0qJmW13XkPZASpt9UDE4qQI488mDqlznDZA2ih',
                                    'message' => '*** Microdigit Microdigit 000 ****',
                                    'name' => 'name 777 after log out test',
                                    'caption' => 'this is caption for action link',
                                    'description' => 'here goes description and links http:anotherfeed.com | http://facebook.com/anotherfeed',
                                    'picture' => 'http://www.google.com/tv/images/slivetv.png',
                                    'link' => 'www.yahoo.com',
                                    'properties' => array(
                                    array('text' => 'test link 1', 'href' => 'http://anotherfeed.com/?ref=1'),
                                    array('text' => 'test link 1', 'href' => 'http://anotherfeed.com/?ref=1'),
                                ),                  
    ));

    echo '<pre>Post ID: ' . $ret_obj['id'] . '</pre>';  

    }else
    {
    $login_url = $facebook->getLoginUrl( array( 'scope' => 'offline_access,publish_stream' ) );
    echo 'Please <a href="' . $login_url . '">login.</a>';
}

} catch(FacebookApiException $e) {

echo $e;

$login_url = $facebook->getLoginUrl( array(                       
                        'scope' => 'offline_access,publish_stream'
                   )); 

echo 'Please <a href="' . $login_url . '">login.</a>';
error_log($e->getType());
error_log($e->getMessage());
}
?>      

But problem is I want to post
that information to page without needing any user interaction.
I mean whenever I run this code, If user is already log off,
my program need user interaction (such as login to facebook) before it post to facebook page.


So I will be appreciated every suggestion that can show me how to post data to facebook without needing any user interaction.

4

1 回答 1

1

根据您要使用的触发器,一种方法是使用Cron Jobs。您可以安排运行 php 脚本。

于 2012-09-16T07:51:11.157 回答