這個應用程序張貼到用戶的時間表,使用PHP和Facebook的PHP API實現。目前這個工作已經進行了幾個星期。狀態消息或帖子隨機發布到Facebook結果
下面的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
));
}
這是否工作正常,除了有在$結果兩種打印格式:
array ('id' => '103240856515XXX',)
array ('id' => '100004900175XXX_103239809849XXX',)
的圖形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代碼生成帖子órs tatus消息。我沒有看到文本消息,照片,日期或作者之間的任何關係。它似乎隨機發生。
下面顯示了我們的數據與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
爲什麼會發生這種行爲?如何強制發佈帖子?這是相關的原因是因爲Post有一個我想查詢的隱私屬性。
更新: 查詢由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從FB API後消息給我:
{
"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": ...
}
查詢一個組合編號,_( '100000226354XXX_545778052106XXX'),這是消息中的照片,給我:
{
"error": {
"message": "Unsupported get request.",
"type": "GraphMethodException",
"code": 100
}
}
我用Graph API Explorer試了一下。用戶10000022635XXX +狀態消息ID爲54577805210XXX將爲'/ 10000022635XXX_54577805210XXX'爲URL,但結果爲GraphMethodException。 '/ me/status /'和'/ me/posts'的數據是獨一無二的:在帖子數據中沒有狀態消息;並且狀態消息數據中沒有帖子。 –
@JeffreyKrist你可以更新這個問題來顯示這兩個JSON響應的佈局(保密信息刪除) – phwd
@pwhd,我已經更新了我的初始文章。 –