There is a good discussion around "how to use Facebook log-in from Google App Engine", but there is one tricky issue dealing with Facebook's app-id/secret-key pair, which is generated for a specific URL.
If you hard-code the id/key pair for your applicatin's URL in your source code, you won't be able to debug it until you deploy.
I've encountered this issue when I was developing fruence.com (groupware for Facebook users), and came up with a simple work around.
Here is the code (the actual app-id and secret-code are replaced by "{app-id}","{secret-code}" to hide them):
@memoize
def _facebook_ids(domain):
dict = {
"www.fruence.com": ("{app-id}","{secret-code}"),
"un-url.appspot.com": ("{app-id}", "{secret-code}"),
"staging.latest.un-url.appspot.com": ("{app-id}", "{secret-code}"),
"localhost:8104": ("{app-id}", "{secret-code}"),
"10.0.1.100:8104": ("{app-id}","{secret-code}"),
}
return dict[domain]
class User(db.Model):
...
@classmethod
def facebook_ids(cls, rh):
url = rh.request.url
(a, domain, b, c, d, e) = urlparse.urlparse(url)
return _facebook_ids(domain)
@classmethod
def current_user(cls, rh):
if not hasattr(rh, "current_user"):
rh.current_user = None
(id, secret) = cls.facebook_ids(rh)
cookie = facebook.get_user_from_cookie(rh.request.cookies, id, secret)
if cookie:
...
Notice that I have generated five app-id/secret-key pairs, including staging environment and local environment (localhost as well as LAN), which allows me to debug my application in any environment.
To see this mechanism in action, access my app from both www.fruence.com and un-url.appspot.com. Each URL has an unique app-id/secret-key pair, but both are connected to the same version of the application. As a Facebook user, you need to "approve" each app separately because they are two different apps from Facebook's point of view (and cookies are associated with each domain), but my application recognize you correctly because the "current_user" is associated with facebook id.
Notice that Facebook allows you to register local URLs like "http://localhost:8104". As far as I can tell, Facebook generates a unique app-id/secret-key pair for each registration, therefore, you don't need to worry about collision.
Viva Google App Engine!
An alternative approach is to temporarily map your domain to localhost using /etc/hosts. Add this line when debugging:
127.0.0.1 www.fruence.com
Comment it out with a leading # when you want to hit the live site.
Posted by: Dirk Diggler | January 06, 2011 at 11:34 AM
Nice post!! kati kura ma sahamati pani laygoa ni tapaile le vaneka क झ samma chai khai k khai k jasto lagyo hai maile dekhe anushar tini haru le matra hoina ki aaru le pani testo kaam garchha ni pahad ko hos ki himal ko sabai koa afnai yeuta chhuttai way hunchhha ni but tyo kaam chai sabaile gareko nai hunchha bachna ko laagi kaam garne saano kaam thulo kaam ani bolai .. riti riwaj tyo ta different hune nai vayo ani aarko chai aba Madhesi group le andolan gareko chha aajawaj uthako chha tiniharu lai pelna hunna sabai nepali vannu parchah vanne kura kasaile force gardaima dimag ma ghusne kura hoina main kura chai Education ho sabailai jankari chai huna paryo ki We are human and We are belong to the same country Nepal vanera uni haru ko maag pura agrdaima satta ma lyaudai ma hune ta kei chahina jo tathabatha chhan uni haru ko bhalai hunchha ani baaki andlond garne morne ko kei na kei hai ani madhesi sahavagita lai hoina aafno ability chha kei garna sakne khubi chha vane ta kasle po rokchha ra Democratic country tei mathi Loktantra k k vako ma ani Nepal sano desh vaye pani madhes vanda pani sarai ani sarai abikasit thau haru dherai chhhan we cant just indicate madhes *हो मधेशीहरु ठूलो संख्यामा विपन्न छन् । अशिक्षित छन् । बेरोजगारी व्यापक छ । सभ्यता पछाडि परेको छ । तर यसमाथि प्रहार गर्ने काम नाजायज हो । मधेशीहरुको विकाश नभई देशको विकास सम्भव छैन । त्यसैले मधेशको विकास जरुरी छ ।* yo ta malai kati ni maan parena .. thanks
Posted by: Amir | July 04, 2012 at 03:38 AM
Dude you gotta realize there are only a few thigns rappers make their songs bout. Money, Bitches, Cars, Pot\Booze. Thats all they got bro.
Posted by: Esbolat | February 13, 2013 at 03:54 AM