本文介绍了在python中使用appsecret_proof进行facebook graph api调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在python中使用appsecret_proof参数进行图形api调用的正确方法是什么?有没有允许这种事情的图书馆?
What is the right way of making graph api calls with appsecret_proof parameter in python? Is there any library that allows such thing?
我试图使用"python for facebook"库,但实际上该文档不存在,所以我无法弄清楚.
I was trying to use 'python for facebook' library but the documentation is literally nonexistent so I can't figure it out.
推荐答案
以下是使用 facebook-sdk 的方法a>:
Here's how you could do that using the facebook-sdk:
import facebook
import hashlib
import hmac
def genAppSecretProof(app_secret, access_token):
h = hmac.new (
app_secret.encode('utf-8'),
msg=access_token.encode('utf-8'),
digestmod=hashlib.sha256
)
return h.hexdigest()
app_secret = "xxxxxxxxx"
access_token = "xxxxxxxxx"
api = facebook.GraphAPI(access_token)
msg = "Hello, world!"
postargs = {"appsecret_proof": genAppSecretProof(app_secret, access_token)}
status = api.put_wall_post(msg, postargs)
经过Python 2.7.9和facebook-sdk 1.0.0-alpha的测试.
Tested with Python 2.7.9 and facebook-sdk 1.0.0-alpha.
这篇关于在python中使用appsecret_proof进行facebook graph api调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!