在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.