I'm trying to create a facebook notifications with facepy & fandjango but I'm constantly get the same Error,
@facebook_authorization_required
@csrf_exempt
def notify_self(request):
token = request.facebook.user.oauth_token.token #user token
token_app=facepy.utils.get_application_access_token('APP_ID','APP_SECRET_ID')
graph = GraphAPI(token)
graph.post(
path = 'me/notifications',
template = '#Text of the notification',
href = 'URL',
access_token= token_app
)
return HttpResponse('<script type=\'text/javascript\'>top.location.href = \'URL\';</script>')<code>
When I Check the app access_token on https://developers.facebook.com/tools/debug/ it said that it's a valid token (I get back my APP's ID)
I also try with
graph = GraphAPI(token_app)
but it send me:
[2500] An active access token must be used to query information about the current user.
my app have all the permission that I need, I search for a while but didn't find any help so I'm asking here.
Edit: The correct Code is
@facebook_authorization_required
@csrf_exempt
def notify_self(request):
token_app=facepy.utils.get_application_access_token('APP_ID','APP_SECRET_ID')
graph = GraphAPI(token_app)
graph.post(
path = 'me/notifications',
template = '#Text of the notification',
href = 'URL'
)
return HttpResponse('<script type=\'text/javascript\'>top.location.href = \'URL\'</script>')
thanks to joaopsf
Finally I found where was the issues. when I was trying with
graph = GraphAPI(token_app)
I was on the good way, the only things to do was to delete
access_token= token_app
the token is saved when at the instruction GraphAPI(token_app) so there is no need to give it again.
The correct code is :
@facebook_authorization_required
@csrf_exempt
def notify_self(request):
token = request.facebook.user.oauth_token.token #user token
token_app=facepy.utils.get_application_access_token('APP_ID','APP_SECRET_ID')
graph = GraphAPI(token)
graph.post(
path = 'me/notifications',
template = '#Text of the notification',
href = 'URL',
access_token= token_app
)
return HttpResponse('<script type=\'text/javascript\'>top.location.href = \'URL\'</script>')
Hope that will help someone