Hi! I have been trying to post on my own wall page but nothing happens till now. I have an app and everytime i was submitted/ everytime a user visits it, i want it to post a link on my own page as page not user. i have this code. but still doesnt work. hope i can find help here. i've been to many forums but no help still. thanks alot in advance!

heres's my code:

$fb_user_id = $facebook->getUser();
$location = "". $facebook->getLoginUrl(array('scope' => 'publish_stream'));
if ($fb_user_id) {
    try {
        $page_access_token = "appid|appsecret";
                    $result = $facebook->api("/me/accounts");
                    foreach($result["data"] as $page) {
                        if($page["id"] == $page_id) {
                            //$page_access_token = $page["access_token"];
                            $page_access_token = $facebook->api("/".FB_PAGE_ID."?fields=access_token");
                            break;
                        }
                    }
        $attachment = array(
        'message' => $post_msg,
        'link' => $post_link,
        'access_token' => $page_access_token,
        );
        $facebook->api("/".FB_PAGE_ID.'/feed', 'POST', $attachment);


    } catch (FacebookApiException $e) {
        $fb_user_id = NULL;
        // seems we don't have enough permissions
        // we use javascript to redirect user instead of header() due to Facebook bug
        print '<script language="javascript" type="text/javascript"> top.location.href="'. $location .'"; </script>';

        // kill the code so nothing else will happen before user gives us permissions
        die();
    }

} else {
    // seems our user hasn't logged in, redirect him to a FB login page

    print '<script language="javascript" type="text/javascript"> top.location.href="'. $location .'"; </script>';

    // kill the code so nothing else will happen before user gives us permissions
    die();
}

Hi Cereal! Yes I'm using that SDK. I have come up with this code. It posts to my page wall, but only when the admin uses the app in the page. i want it to post as admin everytime a user uses the app. Can you take a look at it? thanks a lot for helping :)

require 'libs/facebook.php';
$facebook = new Facebook(array(
    'appId'  => 'xxxxxxxxxxxxxxx',
    'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
));
$loginUrl = $facebook->getLoginUrl();
$user = $facebook->getUser();

$page_id = 'xxxxxxxxxxxxxx';
$page_info = $facebook->api("/$page_id?fields=access_token");


if( !empty($page_info['access_token']) ) {
    $args = array(
        'access_token'  => $page_info['access_token'],
        'message'       => "Post! admin clicks page"
    );
    $post_id = $facebook->api("/$page_id/feed","post",$args);
} else {
    $permissions = $facebook->api("/me/permissions");
    if( !array_key_exists('publish_stream', $permissions['data'][0]) || 
        !array_key_exists('manage_pages', $permissions['data'][0])) {
        header( "Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream, manage_pages")) );
    }

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.