Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6147441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:06:34+00:00 2026-05-23T19:06:34+00:00

I am using the following PHP code to post to my page wall. it

  • 0

I am using the following PHP code to post to my page wall. it is okay I can post successfully as admin but I want to post to the wall using the page name (page account). how do I post using the page name or page id. I tried to find good resource to explain Facebook API function but i did not find good documentation for it.

<?


require '../src/facebook.php';

$app_id = "XXX";
$app_secret = "YYY";

$facebook = new Facebook(array(
 'appId' => $app_id,
 'secret' => $app_secret,
 'cookie' => true
));

$user = $facebook->getUser();
//echo $user;

if(($facebook->getUser())==0)
{
 header("Location:{$facebook->getLoginUrl(array('req_perms' => 'user_status,publish_stream,user_photos,offline_access'))}");
 exit;
}
else {
echo "i am connected";
}

$attachment = array('message' => 'this is my message',
                'name' => 'This is my demo Facebook application!',
                'caption' => "Caption of the Post",
                'link' => 'example.org',
                'description' => 'this is a description',
                'picture' => 'http://example.org/image.gif',
                'actions' => array(array('name' => 'Get Search',
                                  'link' => 'http://www.google.com'))
                );
$status = $facebook->api('/123456789/feed', 'POST', $attachment);   // my page id =123456789
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:06:34+00:00Added an answer on May 23, 2026 at 7:06 pm

    I found the solution to the problem.
    To post or to do any task as a page , you need an access token.
    Here is my final code after the update, I want to share it with you because I found many people having difficulty with getting the correct access code for a page.

        <?
    
    
    require '../src/facebook.php';
    
    $app_id = "XXX";
    $app_secret = "YYY";
    
    $facebook = new Facebook(array(
     'appId' => $app_id,
     'secret' => $app_secret,
     'cookie' => true
    ));
    
    $user = $facebook->getUser();
    //echo $user;
    
    if(($facebook->getUser())==0)
    {
     header("Location:{$facebook->getLoginUrl(array('req_perms' => 'user_status,publish_stream,user_photos,offline_access,manage_pages'))}");
     exit;
    }
    else {
    $accounts_list = $facebook->api('/me/accounts');
    echo "i am connected";
    }
    
    //to get the page access token to post as a page
    foreach($accounts_list['data'] as $account){
          if($account['id'] == 123456789){      // my page id =123456789
            $access_token = $account['access_token'];
            echo "<p>Page Access Token: $access_token</p>";
            }
        }
    
    //posting to the page wall
    $attachment = array('message' => 'this is my message',
                    'access_token'  => $access_token,
                    'name' => 'This is my demo Facebook application!',
                    'caption' => "Caption of the Post",
                    'link' => 'example.org',
                    'description' => 'this is a description',
                    'picture' => 'http://example.org/image.gif',
                    'actions' => array(array('name' => 'Get Search',
                                      'link' => 'http://www.google.com'))
                    );
    $status = $facebook->api('/123456789/feed', 'POST', $attachment);   // my page id =123456789
    var_dump($status);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I am using the following code to navigate to a page in my
I am using the following code for a php page, while I am receiving
I am using the following code. Which is posting fine to a page. But
I am using wordpress and on the page sidebar.php I have the following code:
I am using following PHP code to connect to MS Access database: $odb_conn =
I'm detecting @replies in a Twitter stream with the following PHP code using regexes.
I am using the following code: <?php $stock = $_GET[s]; //returns stock ticker symbol
I'm using php and I have the following code to convert an absolute path
I am using following code to display HTML Form on my web page. This
currently I have following code: home.php <form name='myformname' id='myformid'> <input type='text' name='mytext1' value='abc'> <input

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.