如何让 Facebook 的图形 API 在我的本地主机上工作?

发布于 2024-11-04 05:48:38 字数 123 浏览 1 评论 0原文

标题可能暗示了这一点,但我正在寻找一种方法让 Facebook 的图形 API 在我的本地主机上工作。如果我每次想要测试时都需要将项目同步到服务器,那会很痛苦,因为图表仅在在线时才有效。

有人对这个问题有什么建议吗?

the title might suggest it, but i'm looking for a way to have Facebooks graph API work on my localhost. It's a pain if I need to sync up the project to the server every time I want to test, because graph only works when online.

Does anyone have any suggestions on this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

神妖 2024-11-11 05:48:38

如果您不需要离线访问(这是不可用的,请参阅 Jimmy Sawczuk 的回答),但只需要您的网站能够从本地主机而不是真实域名访问 Graph API,那么应该是可以的。

您需要做的是在 Facebook 上编辑您网站的应用程序的设置。将您的应用程序 URL 设置为“localhost”或您计算机的本地 IP 地址,我认为它应该可以工作。

If you don't need offline access (which is not available, see Jimmy Sawczuk's answer), but only need your website to be able to access the Graph API from your localhost instead of the real domain name, it should be possible.

What you need to do is edit the settings for your site's app on Facebook. Set your applications URL to either 'localhost' or your computers local IP-address, and I think it should work.

余生一个溪 2024-11-11 05:48:38

tl;dr

  1. 设置 facebook 应用程序
  2. 使用 local.yourdomain 编辑 /etc/hosts 文件
  3. 在 local.yourdomain 上使用浏览器

按照本文中描述的说明操作:
如何:本地 Facebook 应用开发

tl;dr

  1. Setup the facebook app
  2. Edit your /etc/hosts file with a local.yourdomain
  3. use your browser on local.yourdomain

Follow the instructions described in this post for the how-to:
How To: Local Facebook App Development

生死何惧 2024-11-11 05:48:38

除非您计划构建一个虚假的 Facebook Graph API 端点,否则您需要在线查询图形 API。

至于运行本地主机,您会发现您需要一个端点来将用户重定向到安装时,否则 Facebook 会抛出错误。您应该能够使用 IP 地址,但域名将为您省去很多麻烦。

当我开发时,我使用一个测试 Facebook 应用程序,它指向我的测试服务器,当我实时推送代码时,它使用基于真实域的真实应用程序。此外,我的测试服务器是一个虚拟机,它通过 Samba 共享访问我计算机上的文件。

希望这有帮助。

Unless you plan on building a fake Facebook Graph API endpoint, then yes, you need to be online to query the graph API.

As for running off of localhost, you'll find that you need an endpoint to redirect users to on an install or Facebook will throw an error. You should be able to use an IP address, but a domain name is going to save you a lot of hassle.

When I'm developing, I use a testing Facebook app that points to my testing server and when I push my code live, it uses the real app which is based on the real domain. Additionally, my testing server is a VM that accesses files on my computer via a Samba share.

Hope this helps.

梦里的微风 2024-11-11 05:48:38

奇怪,但您是否尝试过修改本地 DNS 覆盖(/etc/hosts\WINDOWS\system32\drivers\etc\hosts)以将您提供的域指向你的 Facebook 应用程序位于本地主机吗?这可能有用。

我敢打赌他们使用某种引用 URL 检查,如果他们这样做,你可以在浏览器中访问该 URL,它将路由到本地主机,它将使用正确的引用访问图形 api,你应该是黄金。

让我知道它是否有效。

Odd, but have you tried modifying your local DNS override (either /etc/hosts or \WINDOWS\system32\drivers\etc\hosts) to point the domain you provided to your Facebook app at localhost? That might work.

I'm betting they use some kind of referer URL check, and if they do you can visit the URL in your browser, it will route to localhost, it will hit the graph api with the right referer and you should be golden.

Let me know if it works.

夏了南城 2024-11-11 05:48:38

我正在运行 Rails 3.2.8,这也对我有用。然而,在装有 Mountain Lion 的 Mac 上,我发现最简单的方法是在 localhost 下为站点 URL 的 etc/hosts 文件中的“somedomain.com:3000”创建一个别名,并且不使用应用程序域上的端口号。

I am running rails 3.2.8 and this worked for me too. However on a mac with mountain lion, the easiest way that I found was to create an alias under localhost for 'somedomain.com:3000' in the etc/hosts file for the site url and with out the port # on the app domain.

七色彩虹 2024-11-11 05:48:38

好的。我刚刚花了一天的大部分时间来解决这个问题。如果您无权访问 API 面板来编辑您的 facebook api 允许的域(并且您需要使用 SSL 来伪造它)。

这就是我所做的:

我正在桌面上运行节点服务器。

您需要确保您的节点服务器已经指向您想要在项目中运行/包含的任何文件。 (即,如果您不使用节点进行开发,这个解决方案可能不会帮助您)。

确保您已安装 Express 和 vhost。我使用命令行创建了一个服务器密钥和证书,如下所示:

openssl genrsa -out myKey.pem
openssl req -new -key key.pem -out csr.pem
openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out myCert.pem
rm csr.pem

我将这两个文件移动到我运行服务器实例的当前节点目录中。

我创建了这样的服务器实例:

var vhost = require('vhost'),
express = require('express'),

vhost: {

     'default': 'www.mybigfakeserver.com'   // this should match what your api key allows
},

require('https').createServer({
        key: fs.readFileSync('myKey.pem'),
        cert: fs.readFileSync('myCert.pem')
}, app).listen(443);

在您的主机文件中添加您需要伪造的任何内容。例如

127.0.0.1 www.mybigfakeserver.com

这是取自 facebook api 的。您需要将其添加到 HTML 文件中:

<script>

     FB.init({
        appId      : 'PUT YOUR APP KEY HERE',
        version    : 'v2.0',
        status: true
     });
function(d, s, id){
  var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) {return;}
      js = d.createElement(s); js.id = id;
      js.src = "//connect.facebook.net/en_US/sdk.js";
      fjs.parentNode.insertBefore(js, fjs);
 }(document, 'script'
, 'facebook-jssdk'));

</script>

启动您的节点服务器。

浏览到 https://www.mybigfakeserver.com

您应该会看到您的网站。现在它应该能够伪造您的 facebook api,让您认为您正在为该应用程序创建的常规服务器上运行。

去做 facebook 开发,无需一直部署。

OK. I just spent best part of a day working this out. If you don't have access to the API panel to edit what domains your facebook api allows (and you need to use SSL to fake it out).

Here's what I did:

I am running a node server on my desktop.

You'll need to make sure your node server is already pointing at whatever files you want to run/include in your project. (i.e. if you are not using node to develop, this solution is probably not going to help you).

Make sure you have express and vhost installed. I created a server key and certificate using the command line like this:

openssl genrsa -out myKey.pem
openssl req -new -key key.pem -out csr.pem
openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out myCert.pem
rm csr.pem

I moved the two files into my current node directory where I am running my server instance from.

I created the server instance like this:

var vhost = require('vhost'),
express = require('express'),

vhost: {

     'default': 'www.mybigfakeserver.com'   // this should match what your api key allows
},

require('https').createServer({
        key: fs.readFileSync('myKey.pem'),
        cert: fs.readFileSync('myCert.pem')
}, app).listen(443);

Inside your hosts file add whatever you need to fake out. e.g.

127.0.0.1 www.mybigfakeserver.com

This is taken from the facebook api. You will need to add this in your HTML file:

<script>

     FB.init({
        appId      : 'PUT YOUR APP KEY HERE',
        version    : 'v2.0',
        status: true
     });
function(d, s, id){
  var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) {return;}
      js = d.createElement(s); js.id = id;
      js.src = "//connect.facebook.net/en_US/sdk.js";
      fjs.parentNode.insertBefore(js, fjs);
 }(document, 'script'
, 'facebook-jssdk'));

</script>

Fire up your node server.

Browse to https://www.mybigfakeserver.com

You should see your site. It should now be able to fake out your facebook api into thinking you are running on your regular server that the app was created for.

Go do facebook development without having to deploy all the time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文