[英]Create a facebook notification with Django package facepy : [15] (#15) This method must be called with an app access_token
I'm trying to create a facebook notifications with facepy & fandjango but I'm constantly get the same Error, 我正在尝试使用facepy和fandjango创建Facebook通知,但我经常得到相同的错误,
@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) 当我检查https://developers.facebook.com/tools/debug/上的app access_token时,它说它是一个有效的令牌(我收回了我的APP的ID)
I also try with 我也尝试过
graph = GraphAPI(token_app)
graph = GraphAPI(token_app)
but it send me: 但它发给我:
[2500] An active access token must be used to query information about the current user.
[2500]必须使用活动访问令牌来查询有关当前用户的信息。
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>')
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
the token is saved when at the instruction GraphAPI(token_app) so there is no need to give it again. 在指令GraphAPI(token_app)处保存令牌,因此无需再次给它。
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 希望能帮到别人
When creating notifications, you should use the app token , not the user token. 创建通知时,您应该使用应用令牌 ,而不是用户令牌。 So, the token = ... line is not necessary.
因此, token = ...行是没有必要的。
In addition, since you are using an app token rather than an user token, you cannot use " me/... " in the path; 此外,由于您使用的是app令牌而不是用户令牌,因此您无法在路径中使用“ me / ... ”; you must specify the user ID.
您必须指定用户ID。
This is what worked for me: 这对我有用:
@facebook_authorization_required
@csrf_exempt
def notify_self(request):
token_app = facepy.utils.get_application_access_token(
settings.FACEBOOK_APPLICATION_ID,
settings.FACEBOOK_APPLICATION_SECRET_KEY
)
graph = GraphAPI(token_app)
graph.post(
path='%s/notifications' % request.facebook.user.facebook_id,
template='#Text of the notification',
href='my targe URL',
)
return 'etc'
Jiloko Has forgotten to update the code, I tried the code and the correct code is here: Jiloko忘了更新代码,我尝试了代码,正确的代码在这里:
@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>')
you can change 'me/notifications' for 'USER_ID/notifications' 您可以为'USER_ID / notifications'更改'我/通知'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.