Get user's name from Facebook Graph API

后端 未结 5 1752
没有蜡笔的小新
没有蜡笔的小新 2020-12-28 16:40

I would like to know how is it possible to retrieve a string from an external page.

For example: In a PHP website, the user sends a facebook id, ex: 1157251270

5条回答
  •  再見小時候
    2020-12-28 17:15

    The Graph API returns JSON strings, so you can use:

    echo json_decode(file_get_contents('http://graph.facebook.com/1157251270'))->name;
    

    or more verbose:

    $pageContent = file_get_contents('http://graph.facebook.com/1157251270');
    $parsedJson  = json_decode($pageContent);
    echo $parsedJson->name; // Romanos Fessas
    

    See json_decode — Decodes a JSON string

提交回复
热议问题