Facebook Graph API에 사용할 Django 라이브러리는 무엇입니까? (Which Django library to use for Facebook Graph API?)


문제 설명

Facebook Graph API에 사용할 Django 라이브러리는 무엇입니까? (Which Django library to use for Facebook Graph API?)

저는 현재 Django에서 애플리케이션을 개발 중이며 그래프 API에 대한 Facebook 인증 및 요청을 구현하려고 합니다. 몇 가지 다른 라이브러리를 보았지만 다음을 수행하는 가장 좋은 방법은 무엇입니까?

  1. 사용자가 Facebook을 통해 로그인하도록 합니다.
  2. Django는 새로운 라이브러리를 만듭니다. 사용자를 지정하고 uid 및 oauth 토큰을 추가합니다.
  3. 그런 다음 Facebook의 Python SDK를 사용하여 Graph API를 호출할 수 있습니다.

이 예. 일반 Django에서 그렇게 간단합니까?


참조 솔루션

방법 1:

My company has built a library that makes integrating Facebook into your Django application dead simple (we've probably built 10‑20 apps with the library, including some with huge amounts of traffic, so it's been battle‑tested).

pip install ecl‑facebook==1.2.7

In your settings, add values for your FACEBOOK_KEY, FACEBOOK_SECRET, FACEBOOK_SCOPE, FACEBOOK_REDIRECT_URL, and PRIMARY_USER_MODEL. You'll also need to add ecl_facebook.backends.FacebookAuthBackend to your AUTHENTICATION_BACKENDS. For example, in settings.py:

# These aren't actual keys, you'll have to replace them with your own :)
FACEBOOK_KEY = "256064624431781"
FACEBOOK_SECRET = "4925935cb93e3446eff851ddaf5fad07"
FACEBOOK_REDIRECT_URL = "http://example.com/oauth/complete"
FACEBOOK_SCOPE = "email"

# The user model where the Facebook credentials will be stored
PRIMARY_USER_MODEL = "app.User"

AUTHENTICATION_BACKENDS = (
    # ...
    'ecl_facebook.backends.FacebookAuthBackend',
)

Add some views in your views.py to handle pre‑ and post‑authentication logic.

from django.contrib.auth import authenticate, login
from django.http import HttpResponseRedirect

from ecl_facebook.django_decorators import facebook_begin, facebook_callback
from ecl_facebook import Facebook

from .models import User

# ...

@facebook_begin
def oauth_facebook_begin(request):
    # Anything you want to do before sending the user off to Facebook
    # for authorization can be done here.
    pass

@facebook_callback
def oauth_facebook_complete(request, access_token, error):
    if error is None:
        facebook = Facebook(token)
        fbuser = facebook.me()
        user, _ = User.objects.get_or_create(facebook_id=fbuser.id, defaults={
            'access_token': access_token})
        user = authenticate(id=user.id)
        login(request, user)
        return HttpResponseRedirect("/")
    else:
        # Error is of type ecl_facebook.facebook.FacebookError. We pass
        # the error back to the callback so that you can handle it
        # however you want.
        pass

Now just hook up these URLs in your urls.py file and you're done.

# ...

urlpatterns = patterns('app.views',
    # ...
    url(r'^oauth/facebook/begin$', 'oauth_facebook_begin'),
    url(r'^oauth/facebook/complete$', 'oauth_facebook_complete'),
)

Hope this helps!

P.S. You can read the rest of the docs here.

방법 2:

We do a lot of Facebook Application development where I work, and so we've developed an open‑source library that makes everything about it really easy.

from django.http import HttpResponse
from fandjango.decorators import facebook_authorization_required

@facebook_authorization_required
def foo(request, *args, **kwargs):
    return HttpResponse("Your name is %s" % request.facebook_user.first_name)

방법 3:

I recommend https://github.com/egnity/fb.py. Got my Django‑based Facebook app up and running in no time. It includes a middleware that allows you to run code like this in your view:

for the user id:

user_id = request.facebook.graph().get_object("me")['id']

for the oauth token:

user_token = request.facebook.auth_token

You can then add the above to your User model as you please. To make Graph API calls, you can still use fb.py's middleware ‑‑ no need for using the primitive python‑sdk. The user_id code above is a perfect example of a Graph API call. There's much more you can do with fb.py. The download includes a sample django project to get you going.

(by Cole GleasondwlzJohannes GorsetSimon Kagwi)

참조 문서

  1. Which Django library to use for Facebook Graph API? (CC BY‑SA 3.0/4.0)

#facebook #facebook-graph-api #Django






관련 질문

cocos2d-x Facebook 통합(집중된 보기 때문에 초점이 있는 보기를 저장할 수 없음) (cocos2d-x Facebook integration (couldn't save which view has focus because the focused view))

썸네일이 있는 Facebook 공유 웹사이트 문제 (Facebook sharing website issue with thumbnail)

정의되지 않은 omniauth_authorize_path 메서드 오류 (Undefined omniauth_authorize_path method Error)

Facebook은 드래그하여 이미지를 닫는 데 어떤 라이브러리를 사용합니까? (What library does Facebook use for dismiss image by dragging?)

모든 애플리케이션에 대한 Android 앱에서 데이터 공유 (Share Data in android app for all applications)

Facebook에 사진 공유 (Share a Photo To Facebook)

Android Facebook API, 친구 목록을 얻는 방법? API 버전이 v2.5인데도 Retuning Data가 null (Android Facebook API, How to get friend list?Retuning Data is null, Even though API version is v2.5)

Facebook 오류 #100: 사진 URL이 제공된 경우 링크를 제공해야 합니다. (Facebook Error #100 : A link must be provided if a picture URL is given)

Facebook Graph API에 사용할 Django 라이브러리는 무엇입니까? (Which Django library to use for Facebook Graph API?)

Facebook "좋아요" 버튼 URL에서 일본어(비라틴어) URL 전달 실패 (Passing Japanese (non-Latin) URLs in Facebook "like" button URL fails)

Facebook iOS SDK를 사용하는 동안 PhoneGap 및 SBJSON 중복 충돌 (PhoneGap and SBJSON duplicate conflict while using Facebook iOS SDK)

Facebook 댓글 소셜 플러그인에 댓글을 추가할 수 있는 API가 있습니까? (Does the Facebook Comments Social Plugin have an API where comments can be added?)







코멘트