使用Django软件包创建一个Facebook通知包:[15](#15)这个方法必须用app access_token调用 [英] Create a facebook notification with Django package facepy : [15] (#15) This method must be called with an app access_token
问题描述
我正试图用脸谱和脸谱创建Facebook通知fandjango但我不断得到相同的错误,
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>
当我在 https://developers.facebook.com/tools/debug/ 它说这是一个有效的令牌(我收到我的APP的ID)
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)
我也尝试使用
graph = GraphAPI(token_app)
graph = GraphAPI(token_app)
但它发送给我:
[2500]活动访问令牌必须用于查询有关当前用户的信息。
[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.
编辑:正确的代码是
@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>')
感谢 joaopsf
推荐答案
最后我发现问题在哪里。
当我尝试使用
Finally I found where was the issues. when I was trying with
graph = GraphAPI(token_app)
graph = GraphAPI(token_app)
我是一个很好的方式,唯一要做的就是删除
I was on the good way, the only things to do was to delete
access_token = token_app
access_token= token_app
当在指令GraphAPI(token_app)时保存令牌,所以不需要再次给它。
the token is saved when at the instruction GraphAPI(token_app) so there is no need to give it again.
正确的代码是:
@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>')
希望能帮助某人
这篇关于使用Django软件包创建一个Facebook通知包:[15](#15)这个方法必须用app access_token调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!