2012-04-16 39 views
3

我只是想將帖子自動發送到Facebook的某些事件到我的公司Facebook頁面。從我目前閱讀的內容看來,它應該是直截了當的,但是我正遇到障礙。如何使用ruby fb_graph發佈Facebook頁面更新?

的一些代碼,我已經和誤差如下一個例子:

user = FbGraph::User.me(access_token) 
    user = FbGraph::User.fetch('PageName') 
    FbGraph.debug! # yields true 
    user.feed!(
    :message => 'Updating via FbGraph', 
    :link => 'https://domain.tld', 
    :name => 'PageName', 
    :description => 'This is a test post to be deleted' 
) 

這將返回以下錯誤:

======= [FbGraph] API REQUEST STARTED ======= 
POST /234062246478665/feed HTTP/1.1 
Content-Type: application/x-www-form-urlencoded 
Content-Length: 124 
Host: graph.facebook.com 

message=Updating+via+FbGraph&link=https%3A%2F%2Fdomain.tld&name=PageName&description=This+is+a+test+post+to+be+deleted 
-------------------------------------------------- 
Status: 403 Forbidden 
Access-Control-Allow-Origin: * 
Cache-Control: no-store 
Content-Type: text/javascript; charset=UTF-8 
Expires: Sat, 01 Jan 2000 00:00:00 GMT 
Pragma: no-cache 
WWW-Authenticate: OAuth "Facebook Platform" "insufficient_scope" "(#200) This API call requires a valid app_id." 
X-FB-Rev: 541309 
X-FB-Debug: JN9/Vt8MN24GNUL34l8TE2cDuCRZZehdUTx2KkOrHQ8= 
X-Cnection: close 
Date: Mon, 16 Apr 2012 18:55:20 GMT 
Content-Length: 0 

{"error":{"message":"(#200) This API call requires a valid app_id.","type":"OAuthException","code":200}} 
======= [FbGraph] API REQUEST FINISHED ======= 
/Users/username/.rvm/gems/[email protected]/gems/fb_graph-2.4.10/lib/fb_graph/exception.rb:55:in `handle_httpclient_error': OAuthException :: (#200) This API call requires a valid app_id. (FbGraph::Unauthorized) 
    from /Users/username/.rvm/gems/[email protected]/gems/fb_graph-2.4.10/lib/fb_graph/node.rb:145:in `handle_response' 
    from /Users/username/.rvm/gems/[email protected]/gems/fb_graph-2.4.10/lib/fb_graph/node.rb:54:in `post' 
    from /Users/username/.rvm/gems/[email protected]/gems/fb_graph-2.4.10/lib/fb_graph/connections/feed.rb:15:in `feed!' 
    from ./test_script.rb:168:in `block in <main>' 
    from /Users/username/.rvm/gems/[email protected]/gems/nokogiri-1.5.2/lib/nokogiri/xml/node_set.rb:239:in `block in each' 
    from /Users/username/.rvm/gems/[email protected]/gems/nokogiri-1.5.2/lib/nokogiri/xml/node_set.rb:238:in `upto' 
    from /Users/username/.rvm/gems/[email protected]/gems/nokogiri-1.5.2/lib/nokogiri/xml/node_set.rb:238:in `each' 
    from ./test_script.rb:85:in `each_with_index' 
    from ./test_script.rb:85:in `<main>' 

developers.Facebook.com/apps - >設置 - >驗證對話框我將Extended Permissions設置爲包括publish_streamstatus_update

我發現curl與同樣獲得確實的工作方式如下:

curl -F 'access_token=MY_BIG_OLE_LONG_TOKEN' -F 'message=testing message' https://graph.facebook.com/MyPage/feed 

我缺少權限的設定某處或不與fb_graph紅寶石寶石正確調用API?

回答

3

您需要查看圖API的page的文檔。檢查字段access_token其中manages_pages。您需要在extended_permission中設置此選項。這裏的關鍵是獲得正確的標記。文本字段中的令牌可能無法在大多數情況下運行。您需要發送GET請求到https://graph.facebook.com/YOUR_PROFILE_ID/accounts以獲取正確的令牌。似乎你已經得到了正確的。

我以前用過koala gem。如發佈here

page_graph = Koala::Facebook::GraphAPI.new(@access_token)
page_graph.put_object('MyPage', 'feed', :message => 'This is posted as the page')

嗯,我必須說,Facebook的API文檔缺乏開發人員友好。你需要深入挖掘才能獲得最簡單的工作。

我希望這會幫助您開始自動化FB帖子。

+0

這有幫助。我碰到的另一件事是,如果你使用測試用戶的頁面。發佈到頁面將失敗。但在真實賬戶上它按預期工作。 – 2013-08-28 19:15:13

相關問題