加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

使用Django包创建一个facebook通知facepy:[15](#15)必须使用app

发布时间:2020-12-20 13:31:07 所属栏目:Python 来源:网络整理
导读:我正在尝试使用facepy创建Facebook通知fan django但我总是得到相同的错误, @facebook_authorization_required@csrf_exempt def notify_self(request): token = request.facebook.user.oauth_token.token #user token token_app=facepy.utils.get_application
我正在尝试使用facepy&创建Facebook通知fan django但我总是得到相同的错误,

@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 access_token时,它说它是一个有效的令牌(我收回了我的APP的ID)

我也尝试过

graph = GraphAPI(token_app)

但它发给我:

[2500] An active access token must be used to query information about the current user.

我的应用程序拥有我需要的所有权限,我搜索了一段时间,但没有找到任何帮助,所以我在这里问.

编辑:正确的代码是

@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',href = 'URL'
   ) 

   return HttpResponse('<script type='text/javascript'>top.location.href = 'URL'</script>')

感谢joaopsf

解决方法

最后我发现了问题所在.
当我尝试时

graph = GraphAPI(token_app)

我是好方法,唯一要做的就是删除

access_token= token_app

在指令GraphAPI(token_app)处保存令牌,因此无需再次给它.

正确的代码是:

@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',access_token= token_app
   ) 

   return HttpResponse('<script type='text/javascript'>top.location.href = 'URL'</script>')

希望能帮到别人

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读