如何使用python从app engine向我的facebook应用程序的墙上写文章?

2024-04-28 17:38:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个app engine web应用程序,它希望自动将帖子写到我控制的facebook应用程序的墙上(即,每当网站上发生特定事件时,我希望更新我的facebook应用程序的墙上)。

此代码将从服务器上的延迟任务调用。

我找不到任何东西来解决这个问题。谢谢你的帮助。

我做的第一件事是用以下代码获取访问令牌:

https://graph.facebook.com/oauth/access_token?client_id=FACEBOOK_APP_ID&client_secret=FACEBOOK_APP_SECRET&grant_type=client_credentials&scope=manage_pages,offline_access

使用返回的访问令牌,这就是我在服务器上运行的:

form_fields = {
    "access_token": FACEBOOK_ACCESS_TOKEN,
    "message": tgText
    };

form_data = urllib.urlencode(form_fields)
result = urlfetch.fetch(url="https://graph.facebook.com/MYAPP_FACEBOOK_ID/feed",
                        payload=form_data,
                        method=urlfetch.POST,
                        validate_certificate=False,
                        headers={'Content-Type': 'application/x-www-form-urlencoded'})

但这么说会导致:

{"error":{"type":"OAuthException","message":"(#200) The user hasn't authorized the application to perform this action"}}

Tags: 代码httpsform服务器comclienttokenid