从Facebook Graph API获取用户名 [英] Get user's name from Facebook Graph API

查看:100
本文介绍了从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

这篇关于从Facebook Graph API获取用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆