0

我只想要生成的输出中的特定值(比如“名称”)。我使用此代码 var_dump($request_object_details);生成以下输出。

我得到什么输出: -

array(6) { ["id"]=> string(26) "514484461930096_1446926141"   ["application"]=> array(2) { ["name"]=> string(18) "Pocket Financetest" ["id"]=> string(15) "270339389736782" } ["to"]=> array(2) { ["name"]=> string(12) "Prince Singh" ["id"]=> string(10) "1446926141" } ["from"]=> array(2) { ["name"]=> string(14) "Ashutosh Singh" ["id"]=> string(15) "100003645579131" } ["message"]=> string(16) "My Great Request" ["created_time"]=> string(24) "2013-01-17T03:45:36+0000" } 

我使用下面的代码来获得上面的输出:

         <?php
        require_once('phps/fbsdk/src/facebook.php');
        $config = array
        (
          'appId' => '270339389736782',
          'secret' => '667e1795cc1f308f312d49d6b1c17cb8',
        );
        $facebook = new Facebook($config);
        //get the request ids from the query parameter
         $request_ids = explode(',', $_REQUEST['request_ids']);

         //build the full_request_id from request_id and user_id
          function build_full_request_id($request_id, $user_id) {
          return $request_id . '_' . $user_id;
         }  

         //for each request_id, build the full_request_id and delete request
     foreach ($request_ids as $request_id)
      {
         $uid = $facebook->getUser();

         $full_request_id = build_full_request_id($request_id, $uid); 
        $request_object_details = $facebook->api("/$full_request_id");
        var_dump($request_object_details);//This is giving me the output

        try {
         $delete_success = $facebook->api("/$full_request_id",'DELETE');
         if ($delete_success) {
            echo "Successfully deleted " . $full_request_id;}
         else {
           echo "Delete failed".$full_request_id;}
        }
        catch (FacebookApiException $e) {
        echo "error=".$e;}
        }
     ?>
4

1 回答 1

0

您的问题尚不清楚,但我仍在为您发布某种代码。

使用json_decode

这样做:它将返回对象

$obj = json_decode($request_object_details);
$result= $obj->id;

或者

您可以使用json_decode并将其转换为数组:

$request_object_details = $facebook->api("/$full_request_id");
$result=json_decode($request_object_details, true);

第二个参数会将解码后的 json 字符串变成一个关联数组。

现在您可以直接使用:

echo $result['id'];
echo $result['application'];

等等...

希望它会帮助你。

于 2013-01-17T06:50:48.840 回答