FQL API issues with array translation?

坚强是说给别人听的谎言 提交于 2020-01-06 13:57:16

问题


Just wanted to know if anyone has come across this issues, I can't seem to fix it - lol.

Using Facebook fql to get all user friends data, it loads 90% of the UID's correct and then loads the others like this " http://fb.com/1.0000411781126E+14 "

It's scaling the UID ... but I am not telling it to all all.

Code:

  // run fql query
  $fql_query_url = 'https://graph.facebook.com/'
    . 'fql?q=SELECT%20uid%2Cfirst_name%2Clast_name%2Cname%2Cemail%2Ccurrent_location%2Cbirthday_date%2C%20contact_email%2Cusername%20FROM%20user%20WHERE%20uid%20IN%20(SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%20%3D%20me())%0A'
    . '&access_token=' . $access_token;
  $fql_query_result = file_get_contents($fql_query_url);
  $fql_query_obj = json_decode($fql_query_result, true);

  // display results of fql query
 // echo '<pre>';
  //print_r("query results:");
  //print_r($fql_query_obj);
  //echo '</pre>';

?>

<table class="dynamicTable colVis table table-striped table-bordered table-condensed table-white">
        <thead>
        <tr>
            <th>Image</th>  
            <th>Full Name</th> 
            <th>Gender</th>
            <th>Locale</th>
            <th>FB Email</th>
            <th>Location</th>
            <!-- <th>Job</th> -->
            <th>Subscribers</th>
            <th>SubscribedTo</th>
            <th>Groups</th>
            <th>Posts</th>
         </tr>
        </thead>

        <?php
         $loopvar = 1;
        foreach ($fql_query_obj['data'] as $eachfriend) {
            $id       = $eachfriend['uid'];
            $name     = $eachfriend['name'];
            $username = $eachfriend['username'];

            //if(array_key_exists('work', $eachfriend)){
            //  $current_work = $eachfriend['work'][0]['employer']['name'];
            //}
            // else
            //  $current_work = "<span style='color:red;'>None</span>";



        echo "<tr>";
        echo "<td><a target='_blank' href='http://fb.com/".$id."'><img src='http://graph.facebook.com/" . $id . "/picture'/></a></td>";
        // echo "<td><a target='_blank' href='http://fb.com/".$id."'>" . $id . "</a></td>";
        echo "<td>" . $name . "</td>";

回答1:


Try this

$fql_query_obj = json_decode(preg_replace('/"uid":(\d+)/', '"uid":"$1"', $fql_query_result),true);

Answered here same issue

How to handle the big int facebook uid returned by FQL?




回答2:


Using json_decode() You can convert large integers to strings

Just Check with this.

 $fql_query_obj = json_decode($fql_query_result, true, 512, JSON_BIGINT_AS_STRING)


来源:https://stackoverflow.com/questions/20931751/fql-api-issues-with-array-translation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!