我在哪里可以使用Rails 3中的FBGraph gem获取访问令牌以发布到我的Facebook页面? [英] Where do I get an access token from to post to my facebook page using FBGraph gem in Rails 3?

查看:118
本文介绍了我在哪里可以使用Rails 3中的FBGraph gem获取访问令牌以发布到我的Facebook页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用FBGraph宝石从我的网站发布到我的Facebook帐户的页面,但如何获取我的访问令牌?
我确定我的代码是正确的发布到我需要的页面

  def send_fb_message(params = {} )
owner = FbGraph :: User.me(FB_TOKEN)
pages = owner.accounts
page = pages.detect do | page |
page.identifier == FB_PAGE_ID
end
page.feed!(
:message => params [:message],
:description => params [ :description],
:link => params [:link])
end



你可以看到FB_TOKEN是一个常量,也许它应该是一个变量,但无论如何,我不知道如何获取访问令牌的值。 (所有权限都已被我的Facebook帐户包含manage_pages权限所接受。)



我有一个秘密和一个应用程序ID为我的Facebook应用程序,我正在使用图形API但是似乎没有地方可以使用这些。



应用程序登录文件在这里 http://developers.facebook.com/docs/authentication/#applogin 根本不清楚我如何获取访问令牌是否有更好的方法?



更新



感谢@Lego下面的回复我已经能够使用访问令牌工具href =https://developers.facebook.com/tools/access_token/ =nofollow> https://developers.facebook.com/tools/access_token/ 。如果我以我的用户身份登录,我可以看到该帖子,但是如果我没有登录,我无法看到该帖子
我该如何使此帖公开?

解决方案

解决方法将是(但只有没有其他帮助!)要求你自己的offline_access权限,并通过访问令牌工具。然后,您可以将访问令牌硬编码到您的网站(服务器端)。由于您向应用程式提供了offline_access权限,令牌不应过期。


I am posting to a page on MY Facebook account from my web site using FBGraph gem but how do I get my access token? I am certain that my code is correct to post to the page I need

  def send_fb_message(params = {})
    owner = FbGraph::User.me(FB_TOKEN)
    pages = owner.accounts
    page = pages.detect do |page|
      page.identifier == FB_PAGE_ID
    end
    page.feed!(
      :message => params[:message],
      :description => params[:description],
      :link => params[:link]        )
  end

As you can see FB_TOKEN is a constant, perhaps it should be a variable but whatever it needs to be I have no idea how to get the value for the access token. (All permissions have been accepted by my facebook account including manage_pages permission.)

I have a secret and an app id for my Facebook app and I'm using the graph api but there seems to be nowhere for me to make use of these.

The app login docs here http://developers.facebook.com/docs/authentication/#applogin don't make it clear to me at all as to how to obtain the access token neither does the docs for the FBGraph gem unless I am missing something?

Is there a better way?

UPDATE

Thank's to the reply from @Lego below I have been able to make this post work using a token using the access token tool https://developers.facebook.com/tools/access_token/. I can see the post if I am logged in as my user but I am unable to see the post if I am not logged in How do I make this post public?

解决方案

A workaround would be (but only if nothing else helps!) to ask yourself the offline_access permission and get yourself an access token via the Access Token Tool or the Graph API Explorer. Then you could hardcode the access token into your website (serverside). Since you gave your app the offline_access permission the token should not expire.

这篇关于我在哪里可以使用Rails 3中的FBGraph gem获取访问令牌以发布到我的Facebook页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆