我试图从用户那里提取用户信息。我能够使用 fql 得到它。但主要问题是我无法将特定数据(例如名称)存储在单独的变量中,我想在网页的文本框中显示该值。任何人都可以告诉我有什么问题吗?
<?php
$app_id = '237773783026***';
$app_secret = '90a6514ebed8***f47a3d9a695608315';
$my_url = 'http://apps.facebook.com/anubhawfirst';
$code = $_REQUEST["code"];
// auth user
if(empty($code)) {
$dialog_url = 'https://www.facebook.com/dialog/oauth?client_id='
$app_id . '&redirect_uri=' . urlencode($my_url) ;
echo("<script>top.location.href='" . $dialog_url . "'</script>");
}
// get user access_token
$token_url = 'https://graph.facebook.com/oauth/access_token?client_id='
$app_id . '&redirect_uri=' . urlencode($my_url)
. '&client_secret=' . $app_secret
. '&code=' . $code;
// response is of the format "access_token=AAAC..."
$access_token = substr(file_get_contents($token_url), 13);
// run fql query
$fql_query_url = 'https://graph.facebook.com/'
. 'fql?q=SELECT+name+,+uid+FROM+user+WHERE+uid=me()'
. '&access_token=' . $access_token;
$fql_query_result = file_get_contents($fql_query_url);
$fql_query_obj = array(json_decode($fql_query_result, true));
//this is the part where am trying to extract using array.
foreach ($fql_query_obj as $item)
{
print $fql_query_obj[0];
;
}
// display results of fql query
echo '<pre>';
print_r("query results:");
print_r($fql_query_obj);
echo '</pre>';
?>