通过API作为页面发布到Facebook页面(具有管理员权限)

问题描述:

我想在Ruby中运行一个后台服务,每天一次发布到我的Facebook页面。最好的方法是什么?我已经阅读了Graph API,但是他们的大部分文档都是依赖于第一个请求用户的权限。如何授予我自己使用的权限,而不是我的应用程序的最终用户?例如,Twitter为您提供身份验证令牌以连接到您自己的帐户。

I'd like to run a background service in Ruby to post to my Facebook page once a day. What's the best way to do this? I've read through the Graph API, but most of their documentation relies on first requesting permissions from the User. How do I grant those permissions for my own use and not the end user of my app? For example, Twitter gives you authentication tokens to connect to your own accounts.

这里有很多关于Graph API的答案已经过时了。我使用Ruby,所以有任何关于宝石或其网站上任何SDK的建议。

A lot of the answers about the Graph API here are outdated. I'm using Ruby, so any recommendations for gems or any of the SDKs on their website.

更新

感谢@oldergod的回复。我有一个更新的问题。

Thanks to @oldergod for the response. I have an updated question.

当我这样做时,我可以将 myPageName 发布到 myPageName 的墙。

When I do this, I am able to post as the myPageName to myPageName's wall.

@graph.put_connections("myPageName", "feed", :message => "I am writing on my wall!")

但是当我这样做:

@graph.put_connections("me", "feed", :message => "I am writing on my wall!", :link => "http://google.com")

它发布到 myPageName 作为

我做错了什么?我已经请求 manage_pages 权限。

What am I doing wrong? I have requested manage_pages permissions.

您正在寻找的宝石是考拉



更新:

看来,您在设置Koala gem的实际配置时遇到一些问题。我们来完成每一步。

As it seems, you are having some problem setting the actual configuration of Koala gem. Let's go through every step.

您需要设置一个新的 Koala :: Facebook :: API 。尽管是一个可怕的名字,但这真的是与您的个人资料用户的连接。要设置这个,你需要访问 Facebook Explorer ,然后点击获取访问令牌按钮(确保您使用要发布消息的帐户登录)。

You need to setup a new Koala::Facebook::API. Despite of being a horrible name, this is really the connection to your profile user. To set up this you need to access the Facebook Explorer and click Get Access Token button (make sure you are logged with the account you wanna post message's to). just copy that access token.

@user = Koala::Facebook::API.new(access_token)

使用该access_token设置新的 @user 。现在,只要在@user上的任何 Graph API 请求中提及,您将会提到该用户(@user)作为该请求的目标。 我只是用户本身的Facebook ID。

Use that access_token to set this new @user. Now whenever you mention "me" in any Graph API request on a @user, you'll be mentioning this user (@user) as the target for that request. "me" is just the facebook ID for the user itself.

最后一步只是发布到用户的Feed页面。

The final step is just to post to your user's feed page.

@user.put_connections("me", "feed", :message => "I am writing on my wall!")






所以,如果你想在墙上张贴一个页面。你可以通过


So, if you want to post as a page on your wall. You can do so by

@user = Koala::Facebook::API.new(access_token)
page_access_token = @user.get_connections('me', 'accounts').first['access_token'] #this gets the users first page.
@page = Koala::Facebook::API.new(page_access_token)
@page.put_connections(user_id, "feed", :message => "Page writting to user's wall!")

只需转到graph.facebook.com/user_path并获取your_ID。

Just go to graph.facebook.com/user_path and get the your_ID.