3

I am new to Facebook apps, I have an app already up and running on GAE (using python). I want to integrate it with Facebook so I can access some of the users' data to help me personalize the app (data like the liked pages, interests, where they are from etc..). And also to share the app's outputs to be seen by friends.

I thought I would go for the Facebook app option on https://developers.facebook.com/

I don't know where to start from, there are some tutorials (most of them are very old, some use scripts that are deprecated so it is a bit worrying), and there's FBML.. and I was thinking that maybe I can get the same data by only using Facebook's log in then use FQL to access these data.

And I don't know if I will get stuck with that new https restriction (Facebook says that it is required as of October 2011 to have an SSL certificate).

So bottom line.. where do I start?

Mohamed Khamis
  • 7,731
  • 10
  • 38
  • 58
  • You may want to have a look at this question http://stackoverflow.com/questions/8675810/understanding-runwithfriends-facebook-app-sample-code/8682790 – Niklas Rosencrantz Jan 06 '12 at 02:19

3 Answers3

3

Here we go:

From this link do download: https://github.com/jgorset/facepy/tree/master/facepy:

from downloads, you will have:
signed_request.py to parse signed_request that will be posted by facebook in your canvas url: https://apps.facebook.com/myapp in POST method

and graph_api.py to make operation to graphapi https://developers.facebook.com/docs/reference/api/

note: you will be including access_token from cookies written by facebook js sdk.
for fb js sdk see this answer: https://stackoverflow.com/a/8625873/492258 of javascript part

in your index page:

fb_app_secret='abcd...'
fb_app_id = 123345
def index(request):
    if request.POST:
        signed_request_param = request.POST.get('signed_request)        
        if signed_request_param:  
            #signed_request.py 
            signed_request_dic = signed_request.parse_signed_request(signed_request_param, fb_app_secret)
             if signed_request_dic:
                if signed_request_dic.has_key('user_id'): 
                    fb_uid = signed_request_dic['user_id']
                    #you got your man that is previously authorized your fb app : mypp

for successive calls, you'll be using cookies that I mentioned above:

def my_page(request):
    my_dict = None
    my_dict = signed_request.get_user_from_cookie(request.COOOKIES, fb_app_id, fb_app_secret)
    if my_dict:
        if my_dict.has_key('uid'):            
            fb_uid = my_dict['uid']
            fb_uid = int(fb_uid)
            #you got your registered user again.

For registration, the easiest way doing from fb js sdk, already I mentioned

#finally for SSL, in your app.ymal:

- url: .*
  script: django_bootstrap.py
  secure: optional 

Don't forget to set P3P for internet explorer, iframre cookie issue:

def my_page(request):
    ....
    response = render_to_response('mypage.html', view_params )
    response["P3P"] = 'CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'   
    return response 
Community
  • 1
  • 1
asdf_enel_hak
  • 7,474
  • 5
  • 42
  • 84
2

You need to authenticate your server app (GAE) against Facebook: you need to implement server-side authentication flow.

See LeanEngine (open-source) for an example implementation: server auth classes.

Once you are past authentication and you get user FB auth token, you can use FB Graph API to get all kinds of data.

Peter Knego
  • 79,991
  • 11
  • 123
  • 154
-2
  1. Buy a SSL cert for your web server, so you can be compliant with the new rules.
  2. Create/Setup your app to get your app id and secret.
  3. Study up on the Javascript SDK, it's the easiest to implement in my humble opinion.
  4. Study up on the Graph API and learn about the objects and their properties as well as their connections.
  5. You can play around with the JS SDK here: https://developers.facebook.com/tools/console/ and the Graph here: https://developers.facebook.com/tools/explorer
  6. Introduce code slowly to your page on your webserver. First get authentication working, then move on to getting basic user information.
DMCS
  • 31,720
  • 14
  • 71
  • 104
  • 1. AppEngine does not support custom server or client certificates. – Peter Knego Jan 05 '12 at 20:32
  • 2. Javascript is useable in FB client-side flow authentication. OP needs server-based athentication. – Peter Knego Jan 05 '12 at 20:33
  • 1
    @Peter, all you do it AJAX up the token grabbed by the JS SDK. I'm sorry AppEngine is so limited to not even allow SSL. I'd suggest finding a new platform to develop on since SSL is now a semi-"requirement" for facebook apps. – DMCS Jan 05 '12 at 21:04
  • So, client grabs token from FB via JS and then passes it to GAE server? Not good, as in this case GAE would have to trust the client. You should never trust the client on the internet. This is the reason Facebook (and OAuth in general) have server-side authentication flows. – Peter Knego Jan 05 '12 at 21:13
  • 2
    Also, GAE has SSL, just not with custom certificates. Every GAE app has a full-valid server certificate provided by google. – Peter Knego Jan 05 '12 at 21:14