从Facebook Graph API获取用户名

从Facebook Graph API获取用户名

问题描述:

我想知道如何从外部页面检索字符串。

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

例如:在PHP网站中,用户发送一个Facebook id ,例如:1157251270

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

该网站从名称 rel =noreferrer> http://graph.facebook.com/1157251270

And the website returns the name from http://graph.facebook.com/1157251270.

我希望我清楚。

谢谢

Graph API返回JSON字符串,因此可以使用: p>

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

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

或更详细:

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

请参阅 json_decode - 解码JSON字符串

See json_decode — Decodes a JSON string