我在为托管在 google 应用程序引擎上的我的 facebook 应用程序显示画布 url 时遇到一些问题,我正在使用 python。
在谷歌应用引擎(www.my-app.appspot.com)上一切正常,但是当我尝试在 facebook 上查看我的应用时,画布完全是空白的。
URL 画布: http: //my-app.appspot.com/ 安全 URL 画布:https ://my-app.appspot.com/
我的配置有问题吗?
谢谢
我在为托管在 google 应用程序引擎上的我的 facebook 应用程序显示画布 url 时遇到一些问题,我正在使用 python。
在谷歌应用引擎(www.my-app.appspot.com)上一切正常,但是当我尝试在 facebook 上查看我的应用时,画布完全是空白的。
URL 画布: http: //my-app.appspot.com/ 安全 URL 画布:https ://my-app.appspot.com/
我的配置有问题吗?
谢谢
Your configurations are correct.
If you are using the https://github.com/pythonforfacebook/facebook-sdk
You will need to make some changes to the example code.
The example.py file defines "get" and "post" methods under the HomeHandler class.
The "get" will not work when the page is running as a Canvas App inside Facebook.com, though it will work when the page is directly called by a browser.
Facebook loads the Canvas App into its iframe using a POST request containing the signed_request argument as detailed here: https://developers.facebook.com/docs/howtos/login/signed-request/
The first step you can take to fix the example.py file is as follows.
This will at least get code showing up inside Facebook:
Comment out the original "post" method:
#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))
Duplicate the "get" method as the "post" method, now both get and post are:
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
)))
Once that is done, you can test within Facebook. "example.html" should display in the iframe, however, by default, "example.html" asks for an image URL to upload. That will no longer work since the original "post" method is commented out.
To fix the functionality, you'll need to create if/then statements in the def post(self): method to handle requests. For instance, you may want to re-integrate the original "post" method by checking for the 'url' argument - using self.request.get('url') - if it is there, then you know you are receiving an image URL and should branch to the original "post" code