2011-07-06 2 views
4

FB 앱이 페이스 북의 앱 페이지에 표시되도록하려하지만 iFrame이 비어 있습니다. 응용 프로그램은 localhost 및 appspot에서 완벽하게 작동하지만 페이스 북에서로드 될 때 아무 일도 일어나지 않습니다.캔버스 iframe에 빈 페이지로 표시되는 앱 엔진의 Facebook 앱

iframe의 소스를 보면 아무 것도 나타나지 않지만이 페이지를 새로 고치면 모든 코드가 정상적으로 표시됩니까?

나는 샌드 박스를 켜고 끄고 시도했으며 localhost 및 appspot에 대해 두 개의 별도 응용 프로그램을 설정했습니다. 둘 다 똑같은 일을합니다.

이 내 주요 응용 프로그램 코드

import cgi 
import datetime 
import urllib 
import wsgiref.handlers 
import os 
import facebook 
import os.path 

from google.appengine.ext import db 
from google.appengine.api import users 
from google.appengine.ext import webapp 
from google.appengine.ext.webapp import util 
from google.appengine.ext.webapp import template 
from google.appengine.ext.webapp.util import run_wsgi_app 


#local 
FACEBOOK_APP_ID = "----------------" 
FACEBOOK_APP_SECRET = "---------------" 

#live 
#FACEBOOK_APP_ID = "--------" 
#FACEBOOK_APP_SECRET = "--------------" 




class User(db.Model): 
    id = db.StringProperty(required=True) 
    created = db.DateTimeProperty(auto_now_add=True) 
    updated = db.DateTimeProperty(auto_now=True) 
    name = db.StringProperty(required=True) 
    location = db.StringProperty(required=False) 
    profile_url = db.StringProperty(required=True) 
    access_token = db.StringProperty(required=True) 
    user_has_logged_in = db.BooleanProperty(required=True) 

class PageModel: 
    def __init__(self, user, friends): 
      self.user = user 
      self.friends = friends 
      #self.length = self.friends['data'].__len__() 








class BaseHandler(webapp.RequestHandler): 
    """Provides access to the active Facebook user in self.current_user 

    The property is lazy-loaded on first access, using the cookie saved 
    by the Facebook JavaScript SDK to determine the user ID of the active 
    user. See http://developers.facebook.com/docs/authentication/ for 
    more information. 
    """ 
    @property 
    def current_user(self): 
     if not hasattr(self, "_current_user"): 
      self._current_user = None 
      cookie = facebook.get_user_from_cookie(
       self.request.cookies, FACEBOOK_APP_ID, FACEBOOK_APP_SECRET) 
      #if logged in 
      if cookie: 

       # get user from db 
       user = User.get_by_key_name(cookie["uid"]) 
       # Store a local instance of the user data so we don't need 
       # a round-trip to Facebook on every request 
       if not user: 
        graph = facebook.GraphAPI(cookie["access_token"]) 
        profile = graph.get_object("me") 
        user = User(key_name=str(profile["id"]), 
           id=str(profile["id"]), 
           name=profile["name"], 
           location=profile["location"]["name"], 
           profile_url=profile["link"], 
           access_token=cookie["access_token"], 
           user_has_logged_in = True) 
        user.put() 
       #else if we do have a user, but their cookie access token 
       #is out of date in the db, update it 

       elif user.access_token != cookie["access_token"]: 
        user.access_token = cookie["access_token"] 
        user.put() 

       self._current_user = user 



     #user = facebook.get_user_from_cookie(self.request.cookies, FACEBOOK_APP_ID, FACEBOOK_APP_SECRET)    
      friends = "chris" 
      pageModel = PageModel(self._current_user, friends) 
      return pageModel 




     return self._current_user 


class Index(BaseHandler): 
    def get(self): 
     path = os.path.join(os.path.dirname(__file__), "index.html") 
     #args = dict(current_user=self.current_user, 
     #   facebook_app_id=FACEBOOK_APP_ID) 
     args = dict(pageModel=self.current_user, 
        facebook_app_id=FACEBOOK_APP_ID) 
     self.response.out.write(template.render(path, args)) 



application = webapp.WSGIApplication([ 
    ('/', Index), 
    ('/savemyaddress', SaveMyAddress) 
], debug=True) 


def main(): 
    run_wsgi_app(application) 
    #util.run_wsgi_app(webapp.WSGIApplication([(r"/", HomeHandler)], debug=True)) 

if __name__ == '__main__': 
    main() 

과 문제는 페이스 북에서 첫 번째 요청은 POST 요청으로 오는 것이 었습니다

<script> 
     window.fbAsyncInit = function() { 
     FB.init({appId: '{{ facebook_app_id }}', 
       status: true, 
       cookie: true, 
       xfbml: true}); 
     FB.Event.subscribe('{% if pageModel.user %}auth.logout{% else %}auth.login{% endif %}', function(response) { 
      window.location.reload(); 
     }); 
     }; 
     (function() { 
     var e = document.createElement('script'); 
     e.type = 'text/javascript'; 
     e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; 
     e.async = true; 
     document.getElementById('fb-root').appendChild(e); 
     }()); 
    </script> 

답변

3

메인 페이지에 내 JS로드입니다

// 초기 facebook 요청은 signed_request가있는 POST로 제공됩니다.

if u'signed_request' in self.request.POST: 
    facebook.load_signed_request(self.request.get('signed_request')) 

http://developers.facebook.com/docs/samples/canvas/

그래서 게시물 요청을 수신하면 문제가 해결됩니다.

관련 문제