Facebook画布网址空白

时间:2012-10-21 11:50:26

标签: facebook google-app-engine

我在使用google应用程序引擎托管的Facebook应用程序上显示画布网址时遇到一些问题,我正在使用python。

在谷歌应用引擎(www.my-app.appspot.com)上,一切都很好,但当我试图在Facebook上看到我的应用时,画布完全是空白的。

网址画布:http://my-app.appspot.com/ 安全网址画布:https://my-app.appspot.com/

我的配置有问题吗?

由于

1 个答案:

答案 0 :(得分:1)

您的配置正确无误。

如果您使用https://github.com/pythonforfacebook/facebook-sdk

您需要对示例代码进行一些更改。

example.py 文件定义HomeHandler类下的“get”和“post”方法。

当Facebook在Facebook.com中作为Canvas App运行时,“get”将不起作用,但是当浏览器直接调用该页面时它将起作用。

Facebook使用包含 signed_request 参数的POST请求将Canvas App加载到其iframe中,如下所示: https://developers.facebook.com/docs/howtos/login/signed-request/

修复example.py文件的第一步如下:

这至少会让代码显示在Facebook内部:

  1. 注释掉原来的“帖子”方法:

    #def post(self):
    #url = self.request.get('url')
    #file = urllib2.urlopen(url)
    #graph = facebook.GraphAPI(self.current_user['access_token'])
    #response = graph.put_photo(file, "Test Image")
    #photo_url = ("http://www.facebook.com/"
                  #"photo.php?fbid={0}".format(response['id']))
    #self.redirect(str(photo_url))
    
  2. 将“get”方法复制为“post”方法,现在get和post都是:

    def post(self):
    template = jinja_environment.get_template('example.html')
    self.response.out.write(template.render(dict(
        facebook_app_id=FACEBOOK_APP_ID,
        current_user=self.current_user
    )))
    
  3. 完成后,您可以在Facebook中进行测试。 “example.html”应显示在iframe中,但默认情况下,“example.html”会要求上传图片网址。由于最初的“post”方法被注释掉,这将不再有效。

    要修复该功能,您需要在 def post(self):方法中创建if / then语句来处理请求。例如,您可能希望通过检查'url'参数重新集成原始的“post”方法 - 使用 self.request.get('url') - 如果它在那里,那么您知道您正在接收图片网址,并且应该分支到原始的“帖子”代码