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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:29:27+00:00 2026-05-31T02:29:27+00:00

I was wondering how to use access token obtained by the getAccessToken() in PHP

  • 0

I was wondering how to use access token obtained by the getAccessToken() in PHP SDK
Following is my code snippet trying to display user email id as well as user activities :
When I run this code emAIL AND USER ACTIVITIES are blank how do I fix this?

      <?php



    require '/home/vespanve/public_html/facebook-php-sdk/src/facebook.php';

    $facebook = new Facebook(array(
      'appId'  => '39653698mmmmm448',
      'secret' => 'd7681299469mmmmmmmmmmmmm',
    ));

    $config = array(
        'appId' => '39653698mmmmm448',
        'secret' => 'd7681299469mmmmmmmmmmmmm',
      );

      $facebook = new Facebook($config);
      $user_id = $facebook->getUser();
    $access_token = $facebook->getAccessToken();
    $facebook->setAccessToken($access_token);

    ?>
    <html>
      <head></head>
      <body>

      <?
        if($user_id) {

// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
          try {

            $fql = 'SELECT name from user where uid = ' . $user_id;
        $fqlmail = 'SELECT email from user where uid = ' . $user_id;
        $fqlact = 'SELECT user_activities from user where uid = ' . $user_id;
            $ret_obj = $facebook->api(array(
                                       'method' => 'fql.query',
                                       'query' => $fql,
                                     ));
        $ret_obj2 = $facebook->api(array(
                                       'method' => 'fql.query',
                      'access_token' => $cookie['access_token'],
                                      'query' => $fqlmail,
                                     ));
        $ret_obj3 = $facebook->api(array(
                                       'method' => 'fql.query',
                      'access_token' => $cookie['access_token'],
                                      'query' => $fqlact,
                                     ));

            // FQL queries return the results in an array, so we have
            //  to get the user's name from the first element in the array.
            echo '<pre>Name: ' . $ret_obj[0]['name'] . '</pre>';
        echo '<pre>Email: ' . $ret_obj2[0]['email'] . '</pre>';
        echo '<pre>Activities: ' . $ret_obj3[0]['user_activities'] . '</pre>';
        $facebook->destroySession();



          } 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.
            $login_url = $facebook->getLoginUrl(); 
            echo 'Please <a href="' . $login_url . '">login.</a>';
            error_log($e->getType());
            error_log($e->getMessage());
          }   
        } else {

// No user, so print a link for the user to login
          $login_url = $facebook->getLoginUrl();
          echo 'Please <a href="' . $login_url . '">login.</a>';

        }
    ?>

      </body>
    </html>
  • 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-31T02:29:28+00:00Added an answer on May 31, 2026 at 2:29 am

    You need to ask for extended permissions:

    $params = array(
      'scope' => 'email, user_activities',
      'redirect_uri' => 'https://www.myapp.com/post_login_page'
    );
    
    $loginUrl = $facebook->getLoginUrl($params);
    

    For more info on this you can chek here:

    http://developers.facebook.com/docs/reference/php/facebook-getLoginUrl/

    For permissions here:

    http://developers.facebook.com/docs/reference/api/permissions/

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

Sidebar

Related Questions

I am wondering if it is possible to use Code Access Security, and a
I want to access a model attribute in Javascript. I use the following code:
I'm wondering how to use a VideoDisplay object (defined in MXML) to display video
I was wondering how to use cin so that if the user does not
I was wondering if I use PHP's hash() function to generate sha512 hashes how
I'm wondering, and hoping, if I can access and use a specific instance of
I use the following, static class to access the data context in my application
On some Microsoft Access queries, I get the following message: Operation must use an
I'm trying to use the built in Make ACCDE functionality in access to make
So I'm trying to use the Graph API with the Facebook JS SDK and

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.