Re: [flask] facebook flask integration
- From:
- Adam Oakman
- Date:
- 2011-03-13 @ 20:40
I use Facebook's python library (https://github.com/facebook/python-
sdk) successfully. The examples they have provided can be used pretty
much as standard without too much modification. So far I am only using
it for authentication like so, I'm using Google App Engine and its
datastore for storage.
cookie = facebook.get_user_from_cookie(
request.cookies,
app.config['FACEBOOK_APP_ID'],
app.config['FACEBOOK_APP_SECRET']
)
if cookie:
flash("We've logged you in using your Facebook credentials.")
user = db.Query(Users).filter('fb_id =', cookie["uid"]).get()
if not user:
graph = facebook.GraphAPI(cookie["access_token"])
profile = graph.get_object("me")
#try by email
user = db.Query(Users).filter('email =',
profile["email"].lower()).get()
if not user:
user = Users()
user.key_name=str(profile["id"])
user.email=profile["email"].lower()
user.fb_id=str(profile["id"])
user.first_name=profile["first_name"]
user.last_name=profile["last_name"]
user.fb_profile_url=profile["link"]
user.fb_access_token=cookie["access_token"]
user.put()
elif user.fb_access_token != cookie["access_token"]:
user.fb_access_token = cookie["access_token"]
user.put()
session_build(user)
return True
else:
return False
On Mar 13, 2011, at 3:08 PM, Abdul Bijur V jA wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hello,
>
> I am pretty new to flask, but love whatever I have seen so far. I
> couldnt find much info on this, but does anyone have any experience
> using flask with facebook? Any sort of examples would be of great
> help.
>
> Cheers,
> Abdul
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iQEcBAEBAgAGBQJNfSQpAAoJEAzTRT3Zfd+IyPEIAICoy1i6EF2uWyx9Cb5G1Gj6
> q7gUX6c7bfT8ayy2oOH+TJBbWlCSGgenYy71MvvqGXbLVA4RsvVJemXfxvbx37ty
> v8Bld9gWnBVez5FwF0mjXkmAtANRf6TEqSXBBit9fpJTylK/nUYQ0O8nRMnzinLv
> iVf26lgTN9zombb8PJx91SDq7FrDRI4xuGStjqq3QKIeI/5l/miT8yVFLFhhBybl
> IeIVWszJzm4vtcWBj7dpVFQEW+PQdP8Lu/x0D3XzY83Y07TQ4/QObvEh2zlbpBsX
> brFBLimVgJnqZeY5PzYp2WEF/mCZnswTFLJTaBTMzA/SDYHNTj7jjsehOUAjDg0=
> =nxBv
> -----END PGP SIGNATURE-----