首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用ruby fb_graph发布Facebook页面更新?

如何使用ruby fb_graph发布Facebook页面更新?
EN

Stack Overflow用户
提问于 2012-04-16 19:11:46
回答 1查看 2.9K关注 0票数 3

我只是想自动发布到Facebook的某些事件到我的公司Facebook页面。从我到目前为止所读到的,它似乎应该是简单明了的,但是我遇到了一个障碍。

我有一些代码的示例,错误如下:

代码语言:javascript
运行
复制
  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'  
  )

这将返回以下错误:

代码语言:javascript
运行
复制
======= [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/ruby-1.9.3-p125@all/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/ruby-1.9.3-p125@all/gems/fb_graph-2.4.10/lib/fb_graph/node.rb:145:in `handle_response'
    from /Users/username/.rvm/gems/ruby-1.9.3-p125@all/gems/fb_graph-2.4.10/lib/fb_graph/node.rb:54:in `post'
    from /Users/username/.rvm/gems/ruby-1.9.3-p125@all/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/ruby-1.9.3-p125@all/gems/nokogiri-1.5.2/lib/nokogiri/xml/node_set.rb:239:in `block in each'
    from /Users/username/.rvm/gems/ruby-1.9.3-p125@all/gems/nokogiri-1.5.2/lib/nokogiri/xml/node_set.rb:238:in `upto'
    from /Users/username/.rvm/gems/ruby-1.9.3-p125@all/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 -> Settings -> Auth Dialog上,我将Extended Permissions设置为包含publish_streamstatus_update

我已经发现,具有相同令牌的curl access确实工作如下:

代码语言:javascript
运行
复制
curl -F 'access_token=MY_BIG_OLE_LONG_TOKEN' -F 'message=testing message' https://graph.facebook.com/MyPage/feed

我是在某个地方遗漏了权限的设置,还是没有正确地使用fb_graph红宝石调用api?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-17 07:27:42

您需要查看图API的页面文档。检查字段access_token哪个manages_pages。您需要在extended_permission中设置此选项。这里的关键是得到正确的标记。文本字段中的令牌在大多数情况下可能无法工作。您需要将GET请求发送到身份证/帐户以获得正确的令牌。看来你已经得到了正确的答案。

我以前用过koala宝石。发布在这里上。

page_graph = Koala::Facebook::GraphAPI.new(@access_token)

page_graph.put_object('MyPage', 'feed', :message => 'This is posted as the page')

我必须说,facebook的API文档缺乏开发人员的友好性。即使是最简单的工作,你也需要深入挖掘。

我希望这将有助于您开始自动化FB的帖子。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10180170

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档