PODIO php API调用,使用应用程序ID过滤获取所有项目字段值的数组偏移量

时间:2017-01-01 04:42:56

标签: php json api podio

我是API新手,我使用的是PODIO链接here的PHP CLient,我希望得到所有项目的所有字段值。

以下代码无效,但如果我使用PodioItem::get_basic(item_id),则可以获取与项目相关的值,但我想获取所有项目的所有字段值,因此我按照应用ID使用过滤器,I'我收到错误Undefined property: PodioItemCollection::$fields

<?php 

require_once '/PodioAPI.php';

$client_id = "xxxx";
$client_secret = "xxxx";
$app_id = xxxx;
$app_token = "xxxx";

Podio::setup($client_id, $client_secret);
Podio::authenticate_with_app($app_id, $app_token);

$item = PodioItem::filter($app_id);
$field_id = 'dashboard-link-2';
$collection = $item->fields[$field_id]->values;

foreach ($collection as $embed) {
  print "Embed id: ".$embed->embed_id."<br>";
  print "Embed URL: ".$embed->original_url."<br>";
}

以下是使用print $item->as_json(true)在JSON格式的APP中提供的2个项目的完整回复。我想在所有字段中for each及其在JSON最后部分的值。

{  
   "item_id":535780740,
   "title":"test",
   "link":"https:\/\/podio.com\/trackzen\/",
   "rights":[  
      "view",
      "comment",
      "rate",
      "add_task",
      "add_file",
      "update",
      "add_conversation",
      "subscribe"
   ],
   "created_on":"2016-12-26 05:58:59",
   "app_item_id_formatted":"2",
   "app_item_id":2,
   "ratings":{  
      "like":{  
         "average":null,
         "counts":{  
            "1":{  
               "total":0,
               "users":[  

               ]
            }
         }
      }
   },
   "last_event_on":"2016-12-30 10:47:34",
   "comment_count":3,
   "created_by":{  
      "type":"user",
      "id":3584284,
      "avatar_type":"file",
      "avatar_id":250835059,
      "image":{  
         "hosted_by":"podio",
         "hosted_by_humanized_name":"Podio",
         "external_file_id":null,
         "link_target":"_blank"
      },
      "name":"Marlon"
      "url":"https:\/\/podio.com\/users
      "avatar":250835059
   },
   "created_via":{  
      "id":1,
      "auth_client_id":1,
      "name":"Podio",
      "display":false
   },
   "initial_revision":{  
      "created_on":"2016-12-26 05:58:59",
      "created_by":{  
         "type":"user",
         "id":3584284,
         "avatar_type":"file",
         "avatar_id":250835059,
         "image":{  
            "hosted_by":"podio",
            "hosted_by_humanized_name":"Podio",
            "file_id":250835059,
            "external_file_id":null,
            "link_target":"_blank"
         },
         "name":"Marlon",
         "url":"https:\/\/podio.com\/users\/",
         "avatar":250835059
      },
      "created_via":{  
         "id":1,
         "auth_client_id":1,
         "name":"Podio",
         "display":false
      }
   },
   "current_revision":{  
      "revision":13,
      "created_on":"2016-12-30 10:47:34",
      "created_by":{  
         "type":"user",
         "id":3584284,
         "avatar_type":"file",
         "avatar_id":250835059,
         "image":{  
            "hosted_by":"podio",
            "hosted_by_humanized_name":"Podio",

            "external_file_id":null,
            "link_target":"_blank"
         },
         "name":"Marlon",
         "url":"https:\/\/podio.com\/users\",
         "avatar":250835059
      },
      "created_via":{  
         "id":1,
         "auth_client_id":1,
         "name":"Podio",
         "display":false
      }
   },
   "fields":{  
      "title":"test",
      "service":[  
         536114669
      ],
      "dashboard-link-2":[  
         {  
            "embed":156461816,
            "file":null
         }
      ],
      "text":" 
TEST 
<\/p>",
      "action":[  
         1
      ],
      "deliverables":[  
         536600856
      ]
   }
}{  
   "item_id":535312848,
   "title":"Test Dashboard",
   "rights":[  
      "view",
      "comment",
      "rate",
      "add_task",
      "add_file",
      "update",
      "add_conversation",
      "subscribe"
   ],
   "created_on":"2016-12-24 09:25:08",
   "app_item_id_formatted":"1",
   "app_item_id":1,
   "ratings":{  
      "like":{  
         "average":null,
         "counts":{  
            "1":{  
               "total":0,
               "users":[  

               ]
            }
         }
      }
   },
   "last_event_on":"2016-12-28 12:37:26",
   "comment_count":23,
   "created_by":{  
      "type":"user",
      "id":3584284,
      "avatar_type":"file",
      "avatar_id":250835059,
      "image":{  
         "hosted_by":"podio",
         "hosted_by_humanized_name":"Podio",,
         "file_id":250835059,
         "external_file_id":null,
         "link_target":"_blank"
      },
      "name":"Marlon",
      "url":"https:\/\/podio.com",
      "avatar":250835059
   },
   "created_via":{  
      "id":1,
      "auth_client_id":1,
      "name":"Podio",
      "display":false
   },
   "initial_revision":{  
      "created_on":"2016-12-24 09:25:08",
      "created_by":{  
         "type":"user",
         "id":3584284,
         "avatar_type":"file",
         "avatar_id":250835059,
         "image":{  
            "hosted_by":"podio",
            "hosted_by_humanized_name":"Podio",
            "external_file_id":null,
            "link_target":"_blank"
         },
         "name":"Marlon",
         "url":"https:\/\/podio.com\/users\/",
         "avatar":250835059
      },
      "created_via":{  
         "id":1,
         "auth_client_id":1,
         "name":"Podio",
         "display":false
      }
   },
   "current_revision":{  
      "revision":6,
      "created_on":"2016-12-28 12:37:26",
      "created_by":{  
         "type":"user",
         "id":3584284,
         "avatar_type":"file",
         "avatar_id":250835059,
         "image":{  
            "hosted_by":"podio",
            "hosted_by_humanized_name":"Podio",
            "thumbnail_link":"https:\/\/d2cmuesa4snpwn.cloudfront.net\/public\/",
            "link":"https:\/\/d2cmuesa4snpwn.cloudfront.net\/public\/",
            "file_id":250835059,
            "external_file_id":null,
            "link_target":"_blank"
         },
         "name":"Marlon",
         "url":"https:\/\/podio.com\/users\/",
         "avatar":250835059
      },
      "created_via":{  
         "id":1,
         "auth_client_id":1,
         "name":"Podio",
         "display":false
      }
   },
   "fields":{  
      "title":"Test Dashboard",
      "service":[  
         535311650,
         536114669
      ],
      "dashboard-link-2":[  
         {  
            "embed":155910622,
            "file":null
         }
      ],
      "action":[  
         1
      ],
      "deliverables":[  
         535312645,
         535312468,
         535312239,
         535312097,
         535311935,
         536114763,
         536114718
      ]
   }
}

1 个答案:

答案 0 :(得分:0)

您希望遍历字段数组以查找external_id等于您要查找的字段。看起来您正在寻找external_id == 'dashboard-link-2'

的字段

编辑#1添加了示例:

$collection = []
foreach ($item->fields as $field) {
  if ($field->external_id == "dashboard-link-2") {
    $collection = $field->values;
  }
}

编辑#2:看一下文档,我的代码适用于较旧/不同版本的库。遗憾