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

  • Home
  • SEARCH
  • 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 4114864
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:30:34+00:00 2026-05-20T22:30:34+00:00

I’m tired of digging through tons of tutorials/documentations which don’t help me at all.

  • 0

I’m tired of digging through tons of tutorials/documentations which don’t help me at all.

What I have now (everything is placed inside admin control panel):

  1. If user is logged on correct account (administrator of page with granted rights), everything works fine, post on page is posted as impersonated site.
  2. If he is logged on other account, nothing happens. Site redirects him to his wall.
  3. If he isn’t logged on any account, he’s redirected to facebook login – if he logs onto correct account, he returns to acp (it’s bad solution, because it’ll clear his form)

I want to achieve:

  1. If logged in, everything as it was
  2. Else popup with login to specific (correct) account

At the moment I’m using only PHP, but solution with JS is permitted.

My code:

<?php
/*(...)*/
$facebook = new Facebook(array(
      'appId'  => $apiid,
      'secret' => $secret,
      'cookie' => true,
    ));

    $session = $facebook->getSession();
    $me = null;
    if ($session) {
        try {
            $uid = $facebook->getUser();
            $me = $facebook->api('/me');
        } catch (FacebookApiException $e) {
            error_log($e);
        }

        if($me) {


            //In order to post to the page later on we need to generate an Access Token for that page, to do this we get me-accounts in the following api call
            $accounts = $facebook->api('/me/accounts');

            //Loop through the array off accounts to find the page with a matching ID to the one we need
            foreach($accounts['data'] as $account){
              if($account['id'] == PAGEID){
                $ACCESS_TOKEN = $account['access_token'];
                }
            }
        }

        $message=$data['facebook_text'];
        $attachment = array(
            'message' => $data['facebook_text'],
            'name' => $data['name'],
            'description' => '',
            'link'=>$someurl,
            'access_token' => $ACCESS_TOKEN
        );
        if($image_url != NULL) $attachment['picture'] = $image_url;

        try {
            if($facebook->api('/PAGEID/feed', 'post', $attachment))
            {
                //other stuff
            }
        } catch (FacebookApiException $e) {
            error_log($e);
            //other stuff
        }
    }
    else
    {
        $login_url = $facebook->getLoginUrl();
        header("Location: $login_url");
        exit;
    }
/* (...) */
?>

Solution can’t redirect anywhere, because it’s inside form, so all data’ll be lost.

  • 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-20T22:30:34+00:00Added an answer on May 20, 2026 at 10:30 pm

    I’m not really sure I understand what you want to do here, but this is what I use in a similar situation:

    $session = $this->get_admin_session_of_page ($page_id);
    $session = unserialize ($session);
    $facebook->setSession ($session, false);
    

    In the facebook php SDK there is a method to manually set the session, setSession. I save the page admin user session in DB with serialize, with the offline access and manage pages permission. Then when you need some admin privileges for the application you just unserialize it, and then use setSession. The second parameter is set to FALSE, so that this session is not saved in a cookie and logout the current user.

    This way it’s not important who is logged in, the work is always done as an admin of the page. I think this is safe to use in an automated script, for example to upload a user photo in a page album.
    Of course, you must use caution with this if it gets more involved then that, or implement your own security.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am trying to loop through a bunch of documents I have to put
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.