使用带指数的uid进行Facebook查询


Facebook Query using uid with exponent

我成功地在PHP脚本中使用FQL查询获得了好友id。

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

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

当frienddid为1.0000127513707E+14时,url不返回任何内容

谢谢你的聆听!什么好主意吗?

<?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';
}
?>

This

$uid = '100000414144463';
不是

$uid = 100000414144463;

不加引号是浮点数/整数,加引号是字符串

use 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);