Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Django-Facebook (yet another thread) [RSS Feed]

#1 Dec. 14, 2010 19:37:28

O.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django-Facebook (yet another thread)


Hi all,
Last day I got the bright idea to start building a facebook app in
django. I was convinced that documentation would be good given that
django docs are very well written and facebook is a big project.
Instead....aaaaaaaaaaarrghhhh!!!!!!!!
On facebook side, there are old and messy docs full of stale options
and broken links (they changed something in their developer part of
site...)!
On django side, lot of small and sometimes unfinished project with no
docs, and not compatible with recent version of django or fb api. Just
to cite few:http://github.com/facebook/python-sdkhttps://github.com/ryanmark/django-facebookconnect/tree/master/facebookconnecthttps://github.com/sciyoshi/pyfacebook/https://github.com/tschellenbach/Django-facebookhttps://github.com/dickeytk/django_facebook_oauthhttp://github.com/flashingpumpkin/django-socialregistrationSo my question is: which is the best way to realize TODAY a (not so)
simple hello world application that does some basic tasks such
- ask to fb user the right to publish things on wall and obtain
personal data like all the other fb app
- show my fb name
- publish something "hello world" on wall
- be able to comunicate with my server using post (like the example
for fbconnect should do)

Preventing questions, nowadays:
- pyfacebook seems not to be compatible to django 1.2.x and their
example don't work (at least for me)
- facebook apps are moving to Iframe so that FBML apps will be no
longer accepted from the next year (according to fb roadmap)
- python-sdk, to the best of my knowledge, are the only one supported
by facebook staff. This would be good because I would not like that my
app relies on a stale-in-6-month library. Unfortunately, I didn't
understand how to use it in django to do those tasks.

So, today which is the better choice to write an app that do those
basic tasks? And where can I find some updated documentation ?

Thanks for any clarification! :)

Lorenzo

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Dec. 14, 2010 20:33:39

Aljoša M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django-Facebook (yet another thread)


first step is to setup your fb canvas app to use oauth 2.0 -http://developers.facebook.com/docs/authentication/canvashowto ask use to authorize your app?
you need to point user to proper url -http://developers.facebook.com/docs/authentication/#authenticating-users-in-a-web-applicationthis code generates url to ask user for permissions in 'scope' arg:
===================================================
fb_auth_url = "https://graph.facebook.com/oauth/authorize";
args = {
'client_id': settings.FACEBOOK_API_KEY,
'redirect_uri': 'http://apps.facebook.com/%s/' % getattr(settings,
'FACEBOOK_APP_NAME', None),
'type': 'user_agent',
'display': 'page',
'scope':
'user_photos,user_videos,publish_stream,offline_access,user_birthday,...',
}
url = "%s?%s" % (fb_auth_url, urllib.urlencode(args))
===================================================
full list of permissions ('scope' arg) is available -http://developers.facebook.com/docs/authentication/permissionswhat's next after user authorizes app and ext. permissions?
when user authorizes your app and returns to your app you'll get
'signed_request' on first request.
you can extract data from 'signed_request' with this code:

===================================================
import json # or simplejson as json
import base64
import hashlib
import hmac

# code for facebook signed_request based on/copied from:http://sunilarora.org/parsing-signedrequest-parameter-in-python-bas# additional info:http://stackoverflow.com/questions/3302946/how-to-base64-url-decode-in-pythondef base64_url_decode(inp):
padding_factor = (4 - len(inp) % 4) % 4
inp += "="*padding_factor
return base64.b64decode(unicode(inp).translate(dict(zip(map(ord,
u'-_'), u'+/'))))

def parse_signed_request(signed_request, secret):
l = signed_request.split('.', 2)
encoded_sig = l
payload = l

sig = base64_url_decode(encoded_sig)
data = json.loads(base64_url_decode(payload))

if data.get('algorithm').upper() != 'HMAC-SHA256':
# log.error('Unknown algorithm')
return None
else:
expected_sig = hmac.new(secret, msg=payload,
digestmod=hashlib.sha256).digest()

if sig != expected_sig:
return None
else:
# log.debug('valid signed request received..')
return data
===================================================

ok, so what's in data from 'signed_request'?
data from 'signed_request':
===================================================
data = parse_signed_request(request.GET.get('signed_request'),
settings.FACEBOOK_SECRET_KEY)

# fb uid for user
uid = data.get('user_id')

# with access token you can access graph api and actually do something
# checkhttp://developers.facebook.com/docs/apifor more info
access_token = data.get('oauth_token')
===================================================

so how do i actually do something?
when you have access_token it's pretty simple to use graph api.
to publish something:
===================================================
h = httplib2.Http()
api_url = "http://graph.facebook.com/PROFILE_ID/feed";
args = {...} # provide arguments as described here -http://developers.facebook.com/docs/reference/api/post#publishingresp, content = h.request(api_url, "POST", urlencode(args))
===================================================

i've posted this from my head, maybe i forgot something, so post
additional questions if something doesn't work as expected.
official facebook python-sdk actually works but nobody is maintaining it.

also, if you ever used google apis or anything else that actually
worked prepare yourself for hell know as facebook platform.

Aljosa Mohorovic

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Dec. 15, 2010 12:18:13

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django-Facebook (yet another thread)


In my Facebook applications, I have used a combination of the official
Python SDK <https://github.com/facebook/python-sdk> and the official
JavaScript SDK <http://developers.facebook.com/docs/reference/javascript/>. The JavaScript SDK takes care of authentication,
requesting permissions, and providing an access token, which I then
pass to the Python SDK in order to access information through the API.

There is, as far as I know, no official documentation involving Django
and the Python SDK, but one of the comments on a bug report asking for
a Django example suggested <https://github.com/anentropic/python-sdk/tree/master/examples/newsfeed_django/>. I have not run that code, but
a cursory reading suggests that it would be helpful.

On Dec 14, 2:37 pm, Orazio <ziducai...@autistici.org> wrote:
> Hi all,
> Last day I got the bright idea to start building a facebook app in
> django. I was convinced that documentation would be good given that
> django docs are very well written and facebook is a big project.
> Instead....aaaaaaaaaaarrghhhh!!!!!!!!
> On facebook side, there are old and messy docs full of stale options
> and broken links (they changed something in their developer part of
> site...)!
> On django side, lot of small and sometimes unfinished project with no
> docs, and not compatible with recent version of django or fb api. Just
> to cite few:
>
>http://github.com/facebook/python-sdkhttps://github.com/ryanmark/django-facebookconnect/tree/master/facebo...https://github.com/sciyoshi/pyfacebook/https://github.com/tschellenbach/Django-facebookhttps://github.com/dickeytk/django_facebook_oauthhttp://github.com/flashingpumpkin/django-socialregistration>
> So my question is: which is the best way to realize TODAY a (not so)
> simple hello world application that does some basic tasks such
> - ask to fb user the right to publish things on wall and obtain
> personal data like all the other fb app
> - show my fb name
> - publish something "hello world" on wall
> - be able to comunicate with my server using post (like the example
> for fbconnect should do)
>
> Preventing questions, nowadays:
> - pyfacebook seems not to be compatible to django 1.2.x and their
> example don't work (at least for me)
> - facebook apps are moving to Iframe so that FBML apps will be no
> longer accepted from the next year (according to fb roadmap)
> - python-sdk, to the best of my knowledge, are the only one supported
> by facebook staff. This would be good because I would not like that my
> app relies on a stale-in-6-month library. Unfortunately, I didn't
> understand how to use it in django to do those tasks.
>
> So, today which is the better choice to write an app that do those
> basic tasks? And where can I find some updated documentation ?
>
> Thanks for any clarification! :)
>
> Lorenzo

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 Dec. 15, 2010 16:42:57

d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django-Facebook (yet another thread)


I had the same problems last weekend. This one here helped me a lot
and is actually working:https://github.com/iplatform/pyFaceGraphThe tricky thing is how to get the access_token (Aljosa mentioned the
proper documentation). The graphdevtools-example-application under
"test" is also helpful here to get the token inside your application.

On 14 Dez., 20:37, Orazio <ziducai...@autistici.org> wrote:
> Hi all,
> Last day I got the bright idea to start building a facebook app in
> django. I was convinced that documentation would be good given that
> django docs are very well written and facebook is a big project.
> Instead....aaaaaaaaaaarrghhhh!!!!!!!!
> On facebook side, there are old and messy docs full of stale options
> and broken links (they changed something in their developer part of
> site...)!
> On django side, lot of small and sometimes unfinished project with no
> docs, and not compatible with recent version of django or fb api. Just
> to cite few:
>
>http://github.com/facebook/python-sdkhttps://github.com/ryanmark/django-facebookconnect/tree/master/facebo...https://github.com/sciyoshi/pyfacebook/https://github.com/tschellenbach/Django-facebookhttps://github.com/dickeytk/django_facebook_oauthhttp://github.com/flashingpumpkin/django-socialregistration>
> So my question is: which is the best way to realize TODAY a (not so)
> simple hello world application that does some basic tasks such
> - ask to fb user the right to publish things on wall and obtain
> personal data like all the other fb app
> - show my fb name
> - publish something "hello world" on wall
> - be able to comunicate with my server using post (like the example
> for fbconnect should do)
>
> Preventing questions, nowadays:
> - pyfacebook seems not to be compatible to django 1.2.x and their
> example don't work (at least for me)
> - facebook apps are moving to Iframe so that FBML apps will be no
> longer accepted from the next year (according to fb roadmap)
> - python-sdk, to the best of my knowledge, are the only one supported
> by facebook staff. This would be good because I would not like that my
> app relies on a stale-in-6-month library. Unfortunately, I didn't
> understand how to use it in django to do those tasks.
>
> So, today which is the better choice to write an app that do those
> basic tasks? And where can I find some updated documentation ?
>
> Thanks for any clarification! :)
>
> Lorenzo

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#5 Dec. 16, 2010 00:35:57

Justin M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django-Facebook (yet another thread)


Facebook published a sample GAE application. The code is pretty
straightforward and you can pretty much use the same concepts in your
Django code. I would think that the signed request logic would work
best in middleware.https://github.com/facebook/runwithfriends-Justin

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » Django-Facebook (yet another thread) [RSS Feed]

Board footer

Moderator control

Enjoy the 16th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support