我试图通过userID从gaph.facebook.com中使用preg_match提取Facebook会员名称。该脚本似乎无法正常工作。有人可以帮忙吗?
<?php
$content = file_get_contents('https://graph.facebook.com/myid?fields=id,name,first_name,last_name,picture');
preg_match("'\"name\": \"(.*?)\",'si", $content, $match);
$name = $match[1];
?>
答案 0 :(得分:0)
我不明白为什么你会将preg_match()
与REGEX
一起使用,而不是使用json_decode()
,因为你已经处理了JSON
类型的响应
<?php
$content = file_get_contents('https://graph.facebook.com/{ID}?fields=id,name,first_name,last_name,picture');
$jsonData = json_decode($content);
echo '</br> id: ' .$jsonData->id,
'</br> name: ' .$jsonData->name,
'</br> first_name: ' .$jsonData->first_name,
'</br> last_name: ' .$jsonData->last_name,
'</br> picutre url: '.$jsonData->picture->data->url;
?>