2012-07-04 42 views
0

的奇怪的ID結果我解釋這個最好的方式是向你展示。在64位系統中看起來像float()錯誤。從圖形API獲取故事標籤返回標記爲

當我打電話給/anotherfeed/feed或任何頁面的情況下,與story_tags帖子返回一些id作爲浮動錯誤。

在id中帶浮動錯誤的示例故事標記。 [id] => 1.7153566624E+14

我的問題是,我該如何解決這個問題,或者我做錯了什麼?我正在做的是在foreach語句中循環。

 if($fvalue[story_tags]){ 
       echo 'Tags: '; 
       $sTags=$fvalue[story_tags]; 
      foreach ($sTags as $skey=>$svalue){ 
      foreach ($svalue as $gkey=>$hvalue){ 
       $id=$hvalue[id]; 
       echo ''.$hvalue[name].' '.$id.' '; 
          } 
      } 
     } 

   [story_tags] => Array 
        (
         [0] => Array 
          (
           [0] => Array 
            (
             [id] => 1.7153566624E+14 
             [name] => Another Feed 
             [offset] => 0 
             [length] => 12 
             [type] => page 
            ) 

          ) 

Array 
(
    [data] => Array 
     (
      [0] => Array 
       (
        [id] => 171535666239724_156133294510726 
        [from] => Array 
         (
          [name] => Another Feed 
          [category] => App page 
          [id] => 171535666239724 
         ) 

        [story] => Another Feed shared Non-Profits on Facebook's photo. 
        [story_tags] => Array 
         (
          [0] => Array 
           (
            [0] => Array 
             (
              [id] => 1.7153566624E+14 
              [name] => Another Feed 
              [offset] => 0 
              [length] => 12 
              [type] => page 
             ) 

           ) 

          [20] => Array 
           (
            [0] => Array 
             (
              [id] => 41130665917 
              [name] => Non-Profits on Facebook 
              [offset] => 20 
              [length] => 23 
              [type] => page 
             ) 

           ) 

         ) 

        [picture] => http://photos-d.ak.fbcdn.net/hphotos-ak-ash3/557037_10150932300320918_1908237167_s.jpg 
        [link] => http://www.facebook.com/photo.php?fbid=10150932300320918&set=a.85612830917.95996.41130665917&type=1 
        [name] => Wall Photos 
        [caption] => Have you heard of the @[159208207468539:274:One Day without Shoes] (ODWS) campaign? ODWS is an annual initiative by @[8416861761:274:TOMS] to bring awareness around the impact a pair of shoes can have on a child's life. 

During the 2012 campaign, @[20531316728:274:Facebook] drove 20% of traffic to the ODWS microsite and TOMS even launched a Facebook-exclusive "Barefoot & Blue" giveaway with @[25266987484:274:Essie Nail Polish] for the second year in a row. 

We think this is a pretty cool example of creating exclusive content around an important initiative that keeps people engaged and involved! 
        [properties] => Array 
         (
          [0] => Array 
           (
            [name] => By 
            [text] => Non-Profits on Facebook 
            [href] => http://www.facebook.com/nonprofits 
           ) 

         ) 

        [icon] => http://static.ak.fbcdn.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif 
        [type] => photo 
        [object_id] => 10150932300320918 
        [application] => Array 
         (
          [name] => Photos 
          [id] => 2305272732 
         ) 

        [created_time] => 2012-07-02T17:57:23+0000 
        [updated_time] => 2012-07-02T17:57:23+0000 
        [comments] => Array 
         (
          [count] => 0 
         ) 

       ) 
+1

你是如何進行API調用的?你是否自己做HTTP請求,然後在其上使用json_decode?如果是這樣,請在json_decode上設置選項JSON_BIGINT_AS_STRING。 – CBroe

+0

到目前爲止只是php sdk,在foreach中,我也用cURL來繪製api,使用 $ locs = json_decode($ returned,true); print_r(json_decode($ returned,true)); 我的捲曲示例在這裏http://anotherfeed.com/curl.api.php?pageid=anotherfeed&type=feed 您可以在pageid中輸入任何頁面用戶名進行測試,例如:pageid = facebook pageid = platform pageid = yourpage。 我會測試bigint - 我的解決方案,我希望爲PHP SDK但。 –

+0

我沒有運氣bigint,如果你看看例子中的數組中的id仍然返回相同。 // $ returned =編碼數組。 print_r(json_decode($ returned,JSON_BIGINT_AS_STRING)); –

回答

0

解決方案:

捲曲 - 不得不使用數字格式與PHP_EOL在捲曲解決。

// $ locs = curl call to graph api for/anotherfeed/feed,仍然需要foreach的解決方案。

$locs=json_decode($returned, true); 
$stId=number_format($locs[data][1][story_tags][0][0][id], 0, '', '').PHP_EOL; 
echo $stId; 

PHP-SDK

解決方法是在foreach循環一樣,長的數字需要通過number_format跑出。