Facebook app hosted on Google App Engine

懵懂的女人 提交于 2019-12-05 20:49:40
asdf_enel_hak

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 

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.

  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.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!