Facebook添加评论数据格式

时间:2012-09-14 07:36:51

标签: php facebook facebook-graph-api foreach facebook-comments

我想在facebook帖子上添加评论..来自facebook API

添加评论的功能是

public function fill($json)
{
    if(isset($json['data']))
    {
        $json = $json['data'];
    }
    foreach($json as $k => $v ) $this->{$k} = $v;
}

我将数据以json格式传递为

{"data":{"id":"153870348034313_347443752010304","message":"test comment"}}

但回复是:Invalid argument supplied for foreach()

1 个答案:

答案 0 :(得分:1)

您没有解码JSON

public function fill($json)
{
    $json = json_decode($json);

    if(isset($json->data))
    {
        $json = $json->data;
    }
    foreach($json as $k => $v ) $this->{$k} = $v;
}