user1092302
user1092302

Reputation:

Facebook Query using uid with exponent

I succeed in getting the friends'id with a FQL query in my PHP script.

But some of them looks like 1.0000127513707E+14 instead of 100001275137067. For example, I would like to retrieve the Music Pages he liked I will use :

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

The url does not return anything when friendId is like 1.0000127513707E+14

Thanks for listening! Any ideas?

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

Upvotes: 1

Views: 336

Answers (2)

Toto
Toto

Reputation: 91428

use printf

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

output:

100000145202000

For your case, change this line:

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

by this one:

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

Upvotes: 0

Dejan Marjanović
Dejan Marjanović

Reputation: 19380

This

$uid = '100000414144463';

Instead of

$uid = 100000414144463;

Without quotes it is float/integer, with it, it is string.

Upvotes: 1

Related Questions