skip to Main Content

I want to get the each user’s FB posts by commandline.

like

[email protected]

[email protected]

[email protected]

These are my code.

    $secret = 'xxxxx';
    $key = 'xxxx';
    $url = "https://graph.facebook.com/oauth/access_token?client_id="
    . $key . "&client_secret=" . $secret . "&grant_type=client_credentials";
    print $url. "n";
    $json = json_decode(file_get_contents($url),true);
    var_dump($json['access_token']); // success

    $url2 =  "https://graph.facebook.com/me?fields=posts&access_token=" .$json['access_token'];

    $json2 = json_decode(file_get_contents($url2),true);
    var_dump($json2); // 

Warning: file_get_contents(https://graph.facebook.com/me?fields=posts&access_token=4887415xxxxxxxxxxxxxxx): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request

I succeed to get the access_token, however I think it is facebook app’s accesstoken?? not user’s??

I think I should indicate the who is the user before loading me? api.

However how should I do?

I let every user login on web application AOuth and stored each users facebook_access_token in DataBase (but it valid a few hours????)

2

Answers


    • If you need to store a User Token, you should use an Extended User Token
    • You cannot get a User Token programmatically, only on user interaction with a proper login process
    • You can debug Tokens to see if it is an App or User Token in the Token Debugger

    More Information: https://developers.facebook.com/docs/facebook-login/access-tokens/

    Login or Signup to reply.
  1. grant_type=client_credentials generates an app token.

    App access tokens are used to make requests to Facebook APIs on behalf of an app rather than a user. This can be used to modify the parameters of your app, create and manage test users, or read your apps’s insights.

    Some user data that would normally be visible to an app making a request with a user access token isn’t always visible with an app access token. If you’re reading user data and using it in your app, you should use a user access token instead of an app access token.

    You can not use app tokens to access me or fetch most data about individual users.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search