Facebook查询使用带有指数的uid

时间:2011-12-13 15:34:39

标签: php facebook-fql facebook-apps

我成功地在PHP脚本中使用FQL查询获取了朋友的信息。

但其中一些看起来像1.0000127513707E+14而不是100001275137067。 例如,我想检索他将使用的音乐页面:

https://graph.facebook.com/friendId/music?access_token= ...

当friendId类似于1.0000127513707E + 14

时,网址不会返回任何内容

感谢收听!有什么想法吗?

<?php

// $me, $search and $access_token are $_POST variables

// my FQL query - I select the uid and the name of my friends
$fql_query_url = myUrlEncode('https://graph.facebook.com/fql?q=SELECT uid, name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = "' . $me . '") AND strpos(name,"' . $search . '") >= 0&access_token=' . $access_token);

// getDataFromUrl() is the equivalent of file_get_contents()
$fql_query_url_result = getDataFromUrl($fql_query_url);
$fql_query_url_array = json_decode($fql_query_url_result);

// Number of index
$length_fql_query_url_array = count($fql_query_url_array->data);

if (count($fql_query_url_array->data) > 0) {
  for ($i = 0; $i < $length_fql_query_url_array; $i++) {

    // I display the current friend (name + uid)
    echo '<p>' . $fql_query_url_array->data[$i]->name . '</p>';
    echo '<p>' . $fql_query_url_array->data[$i]->uid . '</p>';

    // I store the current uid
    $wanted_uid = $fql_query_url_array->data[$i]->uid;

    // I retrieve the friend's likes of Music page
    $get_friendMusic = getDataFromUrl('https://graph.facebook.com/' . $wanted_uid . '/music?access_token=' . $access_token);
    $get_friendMusic = json_decode($get_friendMusic);
    $get_friendMusic = objectToArray($get_friendMusic);

    // If there are contents
    if (count($get_friendMusic['data']) != NULL) {
      $get_friendMusic_length = count($get_friendMusic['data']);
      for ($j = 0; $j < $get_friendMusic_length; $j++) {
        $get_friendMusic_names[] = $get_friendMusic['data'][$j]['name'];
      }
    } else {
      $get_friendMusic_names = 'No information';
    }
  }
} else {
  echo 'no result';
}
?>

2 个答案:

答案 0 :(得分:1)

$uid = '100000414144463';

而不是

$uid = 100000414144463;

没有引号,它是float / integer,有了它,它就是字符串。

答案 1 :(得分:0)

使用printf

printf("%14.0f", 1.00000145202E+14);

<强>输出:

100000145202000

对于您的情况,请更改此行:

$get_friendMusic = getDataFromUrl('https://graph.facebook.com/' . $wanted_uid . '/music?access_token=' . $access_token);

这一个:

$get_friendMusic = getDataFromUrl('https://graph.facebook.com/' . sprintf("%.0f", $wanted_uid) . '/music?access_token=' . $access_token);