how to add id and name scope with access token and insert into database using graph api
<p>So I have this code on my script, and I want to scope id and name of the user with the access token and insert it on my database;</p>

<pre><code>    public static function me($data){
    if(User::authenticated()){
        $fb['me'] = @file_get_contents("https://graph.facebook.com/me?access_token={$_SESSION['TOKEN']}");
        $fb['me'] = json_decode($fb['me']);
        return $fb['me']-&gt;$data;
    } else {
        return "ERROR: Not logged in";
    }
}
</code></pre>

<p>}  </p>

<p>It's using facebook's graph api. And also i'd like to scope the facebook user id and name not only the access token. It will be inserted in my database with this query;</p>

<pre><code>if(isset($_POST['act'])){
switch($_POST['act']){
    case "login":
    if(Token::check(Token::extract($_POST['token']))){
        $_SESSION['TOKEN'] = (Token::extract($_POST['token']));
        $insert = $db-&gt;prepare("INSERT INTO {$pref}topkek VALUES('', :token)");
        $insert-&gt;execute(
            array(
                "token" =&gt; $_SESSION['TOKEN']
            )
        );

        if($insert){
            $r = array("status" =&gt; "true", "message" =&gt; "Token validated. Redirecting...");
        } else {
            $r = array("status" =&gt; "false", "message" =&gt; "Query failed.");
        }
    } else {
        $r = array("status" =&gt; "false", "message" =&gt; "Invalid or Expired Token.");
    }
    break;  
</code></pre>

<p>What I want to know is how will it scope the facebook user's id and name when getting the token and to be inserted in the database with the code provided below. And also if the token matches or the user's id matches with a record in database, it will just replace the token with the id that matched.</p>