How to get user token with server side application integration

The goal is extremely simple, but there are no examples on how to retrieve the user token associated with the currently running application.

My goal is to just pull my facebook public page (full open access business page) with an app that I created on facebook that I just created to get the app id and secret so that I can PHP query for the data and then repeat it on my homepage. Very simple, but the documentation on the site is mostly about facebook logins, which I'm not going to do. I just want my channels to be published on the public business page of the site.

This is where I think Facebook is going terribly wrong. Here is my code so far that the queries are correct but generate an empty dataset:

$app_id = "APP_ID";
$app_secret = "APP_SECRET";
$app_token_url = "https://graph.facebook.com/oauth/access_token?"
    . "client_id=" . $app_id
    . "&client_secret=" . $app_secret
    . "&grant_type=client_credentials";

    $response = file_get_contents($app_token_url);
    $params = null;
parse_str($response, $params);

$graph_url = "https://graph.facebook.com/202978003068170/feed?access_token=".$params['access_token'];

$app_details = json_decode(file_get_contents($graph_url), true);


    echo '<pre>';
            var_dump($app_details);
    echo '<pre>';

      

Now let me clarify what the actual meaning is access_token

, because Facebook is vaguely ambiguous on this point. There are actually two types of access tokens and the application I created has both types, which if you are logged in and working on your application you can see here: https://developers.facebook.com/tools/ access_token /

The main problem is the value access_token

that oauth is returning from the above code is "App Token" which has no problem requesting user profile data (which is very scary) but returns empty data when I try to execute a Public Business request the page {"data":[]}

where I have included all permissions. A week later, trying to figure out different methods and slamming my head on the table, and only finding partial salvation through third-party sources of information, I figured out the difference between the two.

I came across a post here that says I have to do a second OAUTH request to pull the user's token "(which I tested the user token associated with the app token from the token debugger in fbook and it works) on Facebook, but what does this request.

Please help someone. It shouldn't be that hard, I don't want users to visit my site using fbook. I just want to display business events, feeds and images on my business website.

thank

+3


source to share





All Articles