2010-10-27 119 views
5

我試圖使用圖形API從Facebook獲取數據。Facebook圖形api - 某些頁面返回空數據集

我所做的要求如下所示:http://graph.facebook.com/<page_name>/,它返回有關頁面的基本數據。如果我確實要求:http://graph.facebook.com/<page_name/feed/,我會收到一個來自此頁面Feed的數據。

有些頁面需要驗證才能訪問它們 - 例如Smirnoff頁面(http://graph.facebook.com/Smirnoff)和其他一些「酒精」頁面(我認爲)。因此,我爲我正在使用的應用程序生成了access_token,並授予它訪問我的帳戶的權限。現在我能爲Smirnoff獲取基本數據,但每當我嘗試訪問低層次的數據(如feedposts),我在JSON得到一個空數組:

{ 
    "data": [ 

    ] 
} 

有什麼從API獲取這些數據的方法?或者被頁面所有者阻止?或者我的授權應用程序需要額外的權限?

回答

0

如果您是該頁面的管理員,則您試圖訪問的大部分內容只能通過API訪問。當您收到一個空數組結果幾乎總是將訪問令牌提供沒有權限訪問您請求什麼情況。如果訪問令牌無效,那麼API實際上會引發錯誤。

+2

好的,但由於本網頁的內容可通過FB www - 我不應該能夠通過API獲得此? – kender 2010-10-27 12:37:44

+1

這是非常煩人的。我們可以澄清一下嗎? 6年後 – 2016-12-16 22:40:11

2

你提到的頁面看起來有點不妥。 我在我的Firefox中嘗試了https://graph.facebook.com/Smirnoff,並收到錯誤消息「false」。

我試過(https://developers.facebook.com/docs/reference/api/)的官方文件中提到的網頁,沒有發現問題。

頁: https://graph.facebook.com/cocacola (可口可樂頁)

{ 
    "id": "40796308305", 
    "name": "Coca-Cola", 
    "picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/203509_40796308305_256509_s.jpg", 
    "link": "https://www.facebook.com/coca-cola", 
    "category": "Food/beverages", 
    "likes": 29964683, 
    "website": "http://www.coca-cola.com", 
    "username": "coca-cola", 
    "founded": "1886", 
    "products": "Coca-Cola is the most popular and biggest-selling soft drink in history, as well as the best-known product in the world.\n\nCreated in Atlanta, Georgia, by Dr. John S. Pemberton, Coca-Cola was first offered as a fountain beverage by mixing Coca-Cola syrup with carbonated water. Coca-Cola was introduced in 1886, patented in 1887, registered as a trademark in 1893 and by 1895 it was being sold in every state and territory in the United States. In 1899, The Coca-Cola Company began franchised bottling operations in the United States.\n\nCoca-Cola might owe its origins to the United States, but its popularity has made it truly universal. Today, you can find Coca-Cola in virtually every part of the world." 
} 

我想我應該得到的消息,警告我說,試圖https://graph.facebook.com/Smirnoff時,我應該使用一個訪問令牌。

好的。讓我繼續。 (請用粗體字替換正確的值。)

  1. 請登錄Facebook並創建Facebook應用程序。

  2. 請訪問此鏈接: https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID & REDIRECT_URI = URL &範圍= user_status,offline_access

  3. 請讓你的Facebook應用程序。

  4. 請通過使用這個鏈接獲得訪問令牌: https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID & client_secret = YOUR_APP_SECRET & grant_type = client_credentials

  5. 通過使用這個鏈接,請獲取應用程序的訪問令牌:https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID & client_secret = YOUR_APP_SECRET & grant_type = client_credenti als

  6. 請訪問您的頁面,並使用剛剛獲得的access_token。

https://developers.facebook.com/docs/reference/api/,支持人員和信息頁的連接包括:

Friends: https://graph.facebook.com/me/friends?access_token=... 
News feed: https://graph.facebook.com/me/home?access_token=... 
Profile feed (Wall): https://graph.facebook.com/me/feed?access_token=... 
Likes: https://graph.facebook.com/me/likes?access_token=... 
Movies: https://graph.facebook.com/me/movies?access_token=... 
Music: https://graph.facebook.com/me/music?access_token=... 
Books: https://graph.facebook.com/me/books?access_token=... 
Notes: https://graph.facebook.com/me/notes?access_token=... 
Permissions: https://graph.facebook.com/me/permissions?access_token=... 
Photo Tags: https://graph.facebook.com/me/photos?access_token=... 
Photo Albums: https://graph.facebook.com/me/albums?access_token=... 
Video Tags: https://graph.facebook.com/me/videos?access_token=... 
Video Uploads: https://graph.facebook.com/me/videos/uploaded?access_token=... 
Events: https://graph.facebook.com/me/events?access_token=... 
Groups: https://graph.facebook.com/me/groups?access_token=... 
Checkins: https://graph.facebook.com/me/checkins?access_token=... 

如果網頁是一個音樂網頁,請嘗試以下鏈接:https://graph.facebook.com/me/music?access_token=ACCESS_TOKEN

請讓我知道我的方法是否有效。謝謝。

+0

似乎酒精相關的網頁只能通過API獲得額外的授權......因此可口可樂和斯米爾諾夫之間的區別。 – kender 2011-06-10 09:15:53

+0

嗨kender,我更新了我的答案。 – Box 2011-06-14 23:56:38

+0

@kender,你知道那些「額外授權」是什麼嗎?我有時收到一些空的帖子數據,我懷疑它正在被檢查...... – PEZ 2011-08-01 17:20:43

2

的頁面需要發佈或者什麼都不顯示出來供

+0

很高興知道!如果頁面已發佈,如何通過圖形api檢查? – Roni 2012-07-16 06:41:54

-3

在我的錯誤尤其是可口可樂。當我在GET中發送我的access_token時,它可以提取他們相冊的照片。如果我不這只是一個空集。