Php 发布到Facebook会随机产生状态消息或帖子

Php 发布到Facebook会随机产生状态消息或帖子,php,facebook,Php,Facebook,此应用程序使用PHP和Facebook的PHP API实现发布到用户的时间线。这项工作正在进行,已经持续了几个星期 以下PHP代码用于发布消息: if($hasPhoto === TRUE) { // Post to FB with picture $facebook->setFileUploadSupport(true); $result = $facebook->api("/me/photos", "post", array( 'mess

此应用程序使用PHP和Facebook的PHP API实现发布到用户的时间线。这项工作正在进行,已经持续了几个星期

以下PHP代码用于发布消息:

if($hasPhoto === TRUE)
{
    // Post to FB with picture
    $facebook->setFileUploadSupport(true);

    $result = $facebook->api("/me/photos", "post", array(
        'message'   => $message,
        'place'     => $place,
        'source'    => '@'  . $photo
    ));
} 
else 
{
    // Post to FB without picture
    $result = $facebook->api("/me/feed", "post", array(
        'message'   => $message,
        'place'     => $place
    ));
}
除了$result有两种格式外,它工作正常:

array ('id' => '103240856515XXX', )
array ('id' => '100004900175XXX_103239809849XXX', )
Graph API文档告诉我们以下内容:

A post from Facebook Platform:  https://graph.facebook.com/19292868552_10150189643478553
A status message on the Facebook Page: https://graph.facebook.com/10150224661566729
这意味着使用的PHP代码生成postsór状态消息。我看不出短信、照片、日期或作者之间有任何关系。这似乎是随机发生的

下面显示了我们的数据中id格式与是否附加照片之间的关系

select count(*) from fbposts where facebookpostid like '%\_%' and hasphoto = 1;  -- 90
select count(*) from fbposts where facebookpostid like '%\_%' and hasphoto = 0;  -- 87
select count(*) from fbposts where facebookpostid not like '%\_%' and hasphoto = 1;  -- 47
select count(*) from fbposts where facebookpostid not like '%\_%' and hasphoto = 0; -- 54
为什么会发生这种行为?如何强制发布?之所以如此,是因为这篇文章确实有一个隐私属性,我想对此提出质疑

更新: 查询FB API给出的带有照片的状态消息545778052106XXX,我得到:

{
  "id": "545778052106XXX", 
  "from": {
    "name": "Jeffrey Krist", 
    "id": "100000226354XXX"
  }, 
  "name": "My message!", 
  "picture": "http://photos-f.ak.fbcdn.net/hphotos-ak-ash3/522827_545778052106XXX_1151562XXX_s.jpg", 
  "source": "http://sphotos-f.ak.fbcdn.net/hphotos-ak-ash3/s720x720/522827_545778052106XXX_1151562XXX_n.jpg", 
  "height": 720, 
  "width": 720, 
  "images": [
    {
      "height": 2048, 
      "width": 2048, 
      "source": "http://sphotos-f.ak.fbcdn.net/hphotos-ak-ash3/s2048x2048/522827_545778052106XXX_1151562XXX_n.jpg"
    },  .. lots more
  ], 
  "link": "https://www.facebook.com/photo.php?fbid=545778052106402&set=p.545778052106XXX&type=1", 
  "icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yz/r/StEh3RhPXXX.gif", 
  "place": {
    "id": "182665821805XXX", 
    "name": "A company name", 
    "location": {
      "street": "My street 13", ..
    }
  }, 
  "created_time": "2012-11-01T08:35:20+0000", 
  "updated_time": "2012-11-01T08:35:20+0000", 
  "comments": ...
  "likes": ...
}
{
  "id": "100003331805XXX_299609210160XXX", 
  "from": {
    "name": "Some name", 
    "id": "100003331805XXX"
  }, 
  "message": "My message", 
  "picture": "http://photos-e.ak.fbcdn.net/hphotos-ak-ash3/560724_299609200160XXX_789651XXX_s.jpg", 
  "link": "https://www.facebook.com/photo.php?fbid=299609200160XXX&set=a.285494101571XXX.69331.100003331805XXX&type=1&relevant_count=1", 
  "name": "Photo album name", 
  "icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yz/r/StEh3RhPXXX.gif", 
  "actions": [
    {
      "name": "Comment", 
      "link": "https://www.facebook.com/100003331805XXX/posts/299609210160XXX"
    }, 
    {
      "name": "Like", 
      "link": "https://www.facebook.com/100003331805XXX/posts/299609210160XXX"
    }
  ], 
  "privacy": {
    "value": "ALL_FRIENDS", ...
  }, 
  "place": {
    "id": "174171872642XXX", ...
  }, 
  "type": "photo", 
  "status_type": "added_photos", 
  "object_id": "299609200160XXX", 
  "application": {
    "name": "My app", ...
  }, 
  "created_time": "2012-12-21T22:33:59+0000", 
  "updated_time": "2012-12-21T23:30:39+0000", 
  "likes":  ...
  "comments": ...
}
{
  "error": {
    "message": "Unsupported get request.", 
    "type": "GraphMethodException", 
    "code": 100
  }
}
使用FB API中的id查询post消息会得到:

{
  "id": "545778052106XXX", 
  "from": {
    "name": "Jeffrey Krist", 
    "id": "100000226354XXX"
  }, 
  "name": "My message!", 
  "picture": "http://photos-f.ak.fbcdn.net/hphotos-ak-ash3/522827_545778052106XXX_1151562XXX_s.jpg", 
  "source": "http://sphotos-f.ak.fbcdn.net/hphotos-ak-ash3/s720x720/522827_545778052106XXX_1151562XXX_n.jpg", 
  "height": 720, 
  "width": 720, 
  "images": [
    {
      "height": 2048, 
      "width": 2048, 
      "source": "http://sphotos-f.ak.fbcdn.net/hphotos-ak-ash3/s2048x2048/522827_545778052106XXX_1151562XXX_n.jpg"
    },  .. lots more
  ], 
  "link": "https://www.facebook.com/photo.php?fbid=545778052106402&set=p.545778052106XXX&type=1", 
  "icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yz/r/StEh3RhPXXX.gif", 
  "place": {
    "id": "182665821805XXX", 
    "name": "A company name", 
    "location": {
      "street": "My street 13", ..
    }
  }, 
  "created_time": "2012-11-01T08:35:20+0000", 
  "updated_time": "2012-11-01T08:35:20+0000", 
  "comments": ...
  "likes": ...
}
{
  "id": "100003331805XXX_299609210160XXX", 
  "from": {
    "name": "Some name", 
    "id": "100003331805XXX"
  }, 
  "message": "My message", 
  "picture": "http://photos-e.ak.fbcdn.net/hphotos-ak-ash3/560724_299609200160XXX_789651XXX_s.jpg", 
  "link": "https://www.facebook.com/photo.php?fbid=299609200160XXX&set=a.285494101571XXX.69331.100003331805XXX&type=1&relevant_count=1", 
  "name": "Photo album name", 
  "icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yz/r/StEh3RhPXXX.gif", 
  "actions": [
    {
      "name": "Comment", 
      "link": "https://www.facebook.com/100003331805XXX/posts/299609210160XXX"
    }, 
    {
      "name": "Like", 
      "link": "https://www.facebook.com/100003331805XXX/posts/299609210160XXX"
    }
  ], 
  "privacy": {
    "value": "ALL_FRIENDS", ...
  }, 
  "place": {
    "id": "174171872642XXX", ...
  }, 
  "type": "photo", 
  "status_type": "added_photos", 
  "object_id": "299609200160XXX", 
  "application": {
    "name": "My app", ...
  }, 
  "created_time": "2012-12-21T22:33:59+0000", 
  "updated_time": "2012-12-21T23:30:39+0000", 
  "likes":  ...
  "comments": ...
}
{
  "error": {
    "message": "Unsupported get request.", 
    "type": "GraphMethodException", 
    "code": 100
  }
}
查询一个组合id(“10000022354xxx\u 545778052106XXX”),这是一条带有照片的消息,我得到:

{
  "id": "545778052106XXX", 
  "from": {
    "name": "Jeffrey Krist", 
    "id": "100000226354XXX"
  }, 
  "name": "My message!", 
  "picture": "http://photos-f.ak.fbcdn.net/hphotos-ak-ash3/522827_545778052106XXX_1151562XXX_s.jpg", 
  "source": "http://sphotos-f.ak.fbcdn.net/hphotos-ak-ash3/s720x720/522827_545778052106XXX_1151562XXX_n.jpg", 
  "height": 720, 
  "width": 720, 
  "images": [
    {
      "height": 2048, 
      "width": 2048, 
      "source": "http://sphotos-f.ak.fbcdn.net/hphotos-ak-ash3/s2048x2048/522827_545778052106XXX_1151562XXX_n.jpg"
    },  .. lots more
  ], 
  "link": "https://www.facebook.com/photo.php?fbid=545778052106402&set=p.545778052106XXX&type=1", 
  "icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yz/r/StEh3RhPXXX.gif", 
  "place": {
    "id": "182665821805XXX", 
    "name": "A company name", 
    "location": {
      "street": "My street 13", ..
    }
  }, 
  "created_time": "2012-11-01T08:35:20+0000", 
  "updated_time": "2012-11-01T08:35:20+0000", 
  "comments": ...
  "likes": ...
}
{
  "id": "100003331805XXX_299609210160XXX", 
  "from": {
    "name": "Some name", 
    "id": "100003331805XXX"
  }, 
  "message": "My message", 
  "picture": "http://photos-e.ak.fbcdn.net/hphotos-ak-ash3/560724_299609200160XXX_789651XXX_s.jpg", 
  "link": "https://www.facebook.com/photo.php?fbid=299609200160XXX&set=a.285494101571XXX.69331.100003331805XXX&type=1&relevant_count=1", 
  "name": "Photo album name", 
  "icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yz/r/StEh3RhPXXX.gif", 
  "actions": [
    {
      "name": "Comment", 
      "link": "https://www.facebook.com/100003331805XXX/posts/299609210160XXX"
    }, 
    {
      "name": "Like", 
      "link": "https://www.facebook.com/100003331805XXX/posts/299609210160XXX"
    }
  ], 
  "privacy": {
    "value": "ALL_FRIENDS", ...
  }, 
  "place": {
    "id": "174171872642XXX", ...
  }, 
  "type": "photo", 
  "status_type": "added_photos", 
  "object_id": "299609200160XXX", 
  "application": {
    "name": "My app", ...
  }, 
  "created_time": "2012-12-21T22:33:59+0000", 
  "updated_time": "2012-12-21T23:30:39+0000", 
  "likes":  ...
  "comments": ...
}
{
  "error": {
    "message": "Unsupported get request.", 
    "type": "GraphMethodException", 
    "code": 100
  }
}

当每个状态消息都是post对象时,无需强制post

状态消息对象
10100948019328597

Post对象
userid\u 10100948019328597

状态消息对象

{
  "id": "10100948019328597", 
  "from": {
    "name": "phwd", 
    "id": "13608786"
  }, 
  "message": "Happy Thanksgiving you cool Canadians!", 
  "updated_time": "2012-10-08T23:17:27+0000", 
  "likes": {
    "data": [
    ], 
    "paging": {
      "next": 
    }
  }
}
Post对象

{
  "id": "13608786_10100948019328597", 
  "from": {
    "name": "phwd", 
    "id": "13608786"
  }, 
  "message": "Happy Thanksgiving you cool Canadians!", 
  "actions": [
    {
      "name": "Comment", 
      "link": "http://www.facebook.com/13608786/posts/10100948019328597"
    }, 
    {
      "name": "Like", 
      "link": "http://www.facebook.com/13608786/posts/10100948019328597"
    }
  ], 
  "privacy": {
    "description": "Public", 
    "value": "EVERYONE", 
    "friends": "", 
    "networks": "", 
    "allow": "", 
    "deny": ""
  }, 
  "type": "status", 
  "status_type": "mobile_status_update", 
  "created_time": "2012-10-08T23:17:28+0000", 
  "updated_time": "2012-10-08T23:17:28+0000", 
  "likes": {
    "data": [
     ]
  }, 
  "comments": {
    "count": 0
  }
}

最好的检查方法是比较
/me/status
/me/posts

我用Graph API Explorer尝试过。用户1000022635xxx+状态消息id 54577805210XXX将“/1000022635xxx_54577805210XXX”作为URL,但结果是GraphMethodException。“/me/statuses/”和“/me/posts”的数据相互比较是唯一的:posts数据中没有状态消息;状态消息数据中没有帖子。@JeffreyKrist您能否更新问题以显示这两个问题的JSON响应布局(机密信息已删除)