啟用偵錯模式後,Graph API 回應可能包含其他欄位,以說明要求的潛在問題。
如要啟用偵錯模式,請使用 debug 查詢字串參數。例如:
curl -i -X GET \
"https://graph.facebook.com/{user-id}
?fields=friends
&debug=all
&access_token={your-access-token}"如果未授予 user_friends 權限,此要求將產生以下回應:
{
"data": [
],
"__debug__": {
"messages": [
{
"message": "Field friends is only accessible on User object, if user_friends permission is granted by the user",
"type": "warning"
},
{
"link": "https://developers.facebook.com/docs/apps/changelog#v2_0",
"message": "Only friends who have installed the app are returned in versions greater or equal to v2.0.",
"type": "info"
}
]
}
}debug 參數值可以設為「all」或與訊息的 type 相應的最低要求嚴重性級別:
| 偵錯參數值 | 傳回內容 |
|---|---|
all | 所有可用的偵錯訊息。 |
info | 類型為 info 和 warning 的偵錯訊息。 |
warning | 只限類型為 warning 的偵錯訊息。 |
偵錯資訊(如有)將以 messages 陣列下 __debug__ 鍵的 JSON 物件形式傳回。此陣列的每個元素都是包含以下欄位的 JSON 物件:
| 欄位 | 資料類型 | 說明 |
|---|---|---|
message | 字串 | 訊息。 |
type | 字串 | 訊息嚴重性。 |
link | 字串 | [選用] 連結相關資訊的網址。 |
您還可以配合 Graph API 測試工具使用偵錯模式。
如果您將建立應用程式並發出 Graph API 要求,確定自己將從哪個版本的 API 獲得回應將會非常有用。例如,如果您在未有指定版本的情況下發出呼叫,系統可能以您不知道的 API 版本作出回應。
Graph API 會為呼叫 facebook-api-version 的回應提供要求標題,表明產生回應的 API 具體版本。例如,以 v2.0 版 API 產生要求的 Graph API 呼叫將會產生以下 HTTP 標題:
facebook-api-version:v2.0
這個 facebook-api-version 標題讓您可以確定 API 呼叫是否會從您預期的 API 版本傳回結果。
透過 Graph API 回報錯誤時,我們會隨您的錯誤報告同時傳送一些其他要求標題,以便我們找出並重現您的問題。這些要求標題為 X-FB-Debug、x-fb-rev 和 X-FB-Trace-ID。