2013-04-02 62 views
1

如何從頁面本身獲取與頁面配對的Facebook對象ID?從頁面URL獲取開放圖形對象ID

例如,我直接問的對象ID 325186347604922我得到:

<pre> 
{ 
    "url": ".../ricetta-bigne_salati.htm", 
    "type": "ricettepercucinare:recipe", 
    "title": "Bignè salati", 
    "image": [ 
    { 
     "url": ".../magazine/wp-content/uploads/2013/03/101-150x150.jpg", 
     "width": 150, 
     "height": 150 
    } 
    ], 
    "description": "Gli ingredienti e la procedura per preparare la ricetta Bignè salati.", 
    "data": { 
    "course": "Antipasto", 
    "foreign_id": 130400 
    }, 
    "updated_time": "2013-03-28T10:12:17+0000", 
    "id": "325186347604922", 
    "application": { 
    "id": "118665634826424", 
    "name": "Ricettepercucinare.com", 
    "url": "https://www.facebook.com/apps/application.php?id=118665634826424" 
    } 
}</pre> 

但如何,例如,此頁http://www.ricettepercucinare.com/ricetta-bigne_salati.htm能知道自己的ID?

謝謝。

+0

爲什麼你需要這個ID?你不可以交換使用這個網址嗎? – Igy

+0

我需要它,因爲我想驗證,當用戶在特定頁面中時,如果該對象包含在用戶完成的此類先前活動中(以符合Open Graph術語,請將其讀作「Story」)它。 –

+0

同樣的問題,你不能使用ID嗎? – Igy

回答

0

目前無法從URL中查找對象ID - 儘管它應該是。

應該使用有可能:

http://graph.facebook.com/?id=http://www.ricettepercucinare.com/ricetta-bigne_salati.htm 

,但是這是行不通的。

請籌集到developers.facebook.com/bugs

0

的錯誤那這傢伙的解決方案:http://blog.odbol.com/?p=9

function facebookGetIdForUrl(url, callback) { 
    //see http://developers.facebook.com/docs/reference/fql/object_url/ 
    FB.api({ 
    method: 'fql.query', 
    query: "SELECT id FROM object_url WHERE url = '" + url + "'" 
    }, function(response) { 
    callback(response[0].id); 
    }); 
} 

facebookGetIdForUrl("http://facebook.com", function (id) { 
    alert("Facebook ID = " + id); 
}); 
+0

添加代碼示例或更多的解釋本來不錯。 –

0

有可能與FQL:

select id, url from object_url where url in ('http://www.watchth.is/movies/9166-baraka') 

See it in the Graph API Explorer,或者乾脆使用這個阿賈克斯電話:https://graph.facebook.com/fql?q=select%20id%2C%20url%20from%20object_url%20where%20url%20in%20('http%3A%2F%2Fwww.watchth.is%2Fmovies%2F9166-baraka')&format=json&suppress_http_code=1

Thanks to Rees' response to a similar question