如何使用 Python/Django 在 Facebook 中获取(和使用)扩展权限

发布于 2024-08-16 21:20:31 字数 798 浏览 11 评论 0原文

我正在尝试编写一个简单的应用程序,让用户授予我的代码写入其页面的 Facebook 流的权限。据我了解,它应该很简单:

  1. 让用户单击一个按钮,启动一个弹出窗口,其中包含我的 Facebook 应用程序中的页面。
  2. 在该页面中,他们单击向我的应用授予 stream_publish 的内容并分配该权限到他们的页面。
  3. 窗口关闭,我现在拥有了在 cron 中运行脚本以将内容推送到该页面的流所需的所有信息。

我已经阅读维基百科好几天了。 pyfacebook 上的注释至少已经过时一年了,人们已经将我指向 socialauth< /a> Django 应用程序似乎同样过时,并且专注于针对用户而不是他们的页面。我什至无法做到上面的#1,更不用说#2 和3 了。

如果有人可以向我展示如何使用 Django/Python 来请求/接收写入 Facebook 流的权限,那将是一个很好的开始。

任何帮助将不胜感激。

I'm trying to write a simple app that lets a user grant my code permission to write to her page's Facebook stream. As I understand it, it should be as easy as:

  1. Have the user click on a button that launches a popup containing the a page in my Facebook app.
  2. In that page, they click on something that grants stream_publish to my app and assigns that permission to their page.
  3. Window closes, I now have all the info I need to run a script in cron to push stuff to that page's stream.

I've been reading the wiki for days. Notes on pyfacebook are at least a year out of date, and people have pointed me to the socialauth app for Django which appears to be equally out of date and focused on targeting users as opposed to their pages. I can't even do #1 up there, let along #2 and 3.

If someone could show me how to use Django/Python to request/receive permission to write to a Facebook stream, that would be a great start.

Any help would be greatly appreciated.

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

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

发布评论

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

评论(2

剧终人散尽 2024-08-23 21:20:31

您看过 minifb 吗?他们的示例页面基本上显示了您请求授权和接收授权所需了解的所有内容会话密钥。 (此外, pyfacebook 的 github 页面 显示该库仍然存在)

因此,对于您的场景,您需要:

  1. 请求“stream_publish”权限。有一些方法可以做到这一点,但我实际上会选择最简单的:提交表单(请注意,我从未做过facebook 的应用程序,我可能错误地认为这种方法是最简单的:-)
  2. 正常使用您的应用程序:使用授权您的应用程序的用户的 user_id 调用 API 方法(您必须存储它),并且,因为你被授权了,它不应该失败。

为此,基本上,在您的模板上添加此表单:

<form promptpermission="publish_stream">
<input type="submit" value="Allow Publish Stream">
</form>

顺便说一下,向 Facebook 开发人员致敬。非常好的官方文档。

编辑:我还不能发表评论,所以:如果您在获取 uid 时遇到问题,请检查这个问题和参考文献。

Have you looked at minifb? Their examples page shows basically everything you need to know to request authorization and receive a session key. (Also, the github page for pyfacebook shows that the library is still alive)

So, for your scenario you'd need:

  1. Request the "stream_publish" permission. There are some ways to do it, but I'd actually go for the easiest: submitting a form (note I've never done an app for facebook, I'm probably wrong assuming this approach is the easiest :-)
  2. Use your application normally: call the API methods using the user_id of the user that authorized your application (you'll have to store it) and, since you were authorized, it shouldn't fail.

For this, basically, add this form on your template:

<form promptpermission="publish_stream">
<input type="submit" value="Allow Publish Stream">
</form>

Kudos to the Facebook developers, by the way. Very nice official documentation.

EDIT: I'm not allowed to comment yet so: Should you face problems getting the uid, check this question and the references.

起风了 2024-08-23 21:20:31

经过大量修改后,我似乎已经解决了 Facebookland 中的所有问题:

  1. 事实证明,让用户单击按钮来授予权限就像 Caio Romão 所说的那样简单。但就我而言,我发现将他们引导至 Facebook 桌面应用程序链接更容易、更可靠。
  2. 使用此链接方法,Facebook 允许您指定 enable_profile_selector=1,这将确保生成一个页面列表,用户可以从中选择哪些页面(如果有)将授予这些权限。
  3. 但对于这一次,Facebook 完全崩溃了。虽然在#2 中,它们允许用户选择一个页面来授予权限,但它们不会通过 POST 或标头将此信息传递到应用程序。它只是不在那里。相反,您必须使用 FQL 做一些丑陋的事情,并向用户提出一些其他问题才能使其发挥作用。

不管怎样,如果有人感兴趣的话,我在我的博客上详细介绍了这一切。感谢您的帮助!

After a lot of tinkering, I appear to have solved all of my problems in Facebookland:

  1. Turns out that having a user click on a button to grant permissions is as easy as Caio Romão said it was. For my part though, I found that directing them to the Facebook Desktop App link was way easier and more dependable.
  2. Using this link method, Facebook allows you to specify enable_profile_selector=1 which will make sure that a list of pages is generated from which the user can select which pages (if any) will grant these permissions.
  3. For this one though, Facebook is totally broken. While in #2 they allow the user to select a page to grant permissions, they don't pass this information onto the application either by way of a POST or in the headers. It's just not there. Instead, you have to do an ugly trick with FQL and some additional questions to the user to make it work.

Anyway, I detailed it all on my blog if anyone is interested. Thanks for your help!

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