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 8514745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:57:14+00:00 2026-06-11T04:57:14+00:00

I was wondering if anyone could help me. I’m trying to use the PHP

  • 0

I was wondering if anyone could help me.

I’m trying to use the PHP SDK to post actions, but it doesn’t seem to return an object after the request is made, nor does it update the activity section of the users profile with the action. I had this working fine in JS but can’t seem to move it to php.

// include the FB SDK
require_once(APPLICATION_PATH . '/../library/facebook/facebook.php');

// create the application instance
$facebook = new Facebook(array(
    'appId'  => $this->facebookConfig->appid,
    'secret' => $this->facebookConfig->appsecret,
    'cookie' => true
));

// get the user id
$user = $facebook->getUser();
if(!empty($user)) {
    // We have a user ID, so probably a logged in user.
    // If not, we'll get an exception, which we handle below.
    try {

        // post og actions
        if(!empty($this->thanksData->ogobject) && !empty($this->thanksData->ogaction)){

            $method = '/me/' . $this->appData->namespace . ':' . $this->thanksData->ogaction;
            $params = array(
                        $this->thanksData->ogobject => 'http://mydomain.com/thanks', 
                        //'access_token' => $this->fbAuthToken
                    );

            $ret_obj = $facebook->api($method, 'POST', $params);

        }

        // wall post
        if(!empty($this->facebookConfig->wallmsg))
            $this->wallPost($facebook);

    } catch(FacebookApiException $e) {
        // If the user is logged out, you can have a 
        // user ID even though the access token is invalid.
        // In this case, we'll get an exception, so we'll
        // just ask the user to login again here.
        $params = array(
            'scope'         => $this->permissions,
            'redirect_uri'  => $this->facebookConfig->applink
        );
        $loginUrl = $facebook->getLoginUrl($params);

        // log errors
        error_log($e->getType());
        error_log($e->getMessage());

        // redirect if not logged in or not enough permissions
        //echo "<script>top.location=\"".$loginUrl."\";</script>";die;
    }

    // Give the user a logout link 
    //echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>';
}

Example of the same in JS
This code was working before I removed it in favour of doing the task in PHP

// initialise facebook
window.fbAsyncInit = function() {

    // get the data
    var data = $('body').data();

    FB.init({
        appId   : data.appid, // App ID
        status  : true, // check login status
        cookie  : true, // enable cookies to allow the server to access the session
        xfbml   : true, // parse XFBML
        oauth   : true  // oauth stuff
    });

    // enable actions on page visit
    if(data.object.length > 0 && data.action.length > 0){

        // check if we have permissions
        FB.login(function(loginResponse){

            FB.api('me/permissions','get',function(response){

                // get the data
                var data = $('body').data();

                if(data.ogactions == 1){
                    var params = {};
                    params[data.object] = data.url;

                    // post that we read the article
                    FB.api(
                        '/me/'+ data.appnamespace + ':' + data.action,
                        'post',
                        params,
                        function(response) {
                            if (!response || response.error) {
                                console.log(response);
                            } else {
                                console.log('Action successful! Action ID: ' + response.id);
                            }
                    });

                }

            });

        }, {scope: 'publish_actions,publish_stream'});

    }
}
  • 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-06-11T04:57:15+00:00Added an answer on June 11, 2026 at 4:57 am

    It was a rather stupid error, my og meta fields in the head had name=”” rather than property=””, something I hadn’t noticed.

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

Sidebar

Related Questions

I was wondering if anyone could help me out, I'm trying to find a
I was wondering if anyone could help me restructure a predefined php array. The
Wondering if anyone could help me? I've recently switched over to Mac and trying
I was wondering if anyone could help me write a PHP script for me
I was wondering if anyone could help me implement color selection in my iOS
Hey there, was wondering if anyone could help a newbie on SQL and Python.
I was wondering if anyone could tell me if what I'm trying to accomplish
I was just wondering if anyone could help me create a mysql function UUID_SHORT()
I was wondering if anyone could help me animate an image on hover that
I was wondering if anyone could help me out (not with code, although that

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.