Facebook要求我创建appsecret_proof:https: //developers.facebook.com/docs/graph-api/securing-requests
我使用以下代码完成了此操作:
public string FaceBookSecret(string content, string key) { var encoding = new System.Text.ASCIIEncoding(); byte[] keyByte = encoding.GetBytes(key); byte[] messageBytes = encoding.GetBytes(content); using (var hmacsha256 = new HMACSHA256(keyByte)) { byte[] hashmessage = hmacsha256.ComputeHash(messageBytes); return Convert.ToBase64String(hashmessage); } }
一切看起来都不错,但facebook说appsecret_proof无效.我已登录,当我删除密钥时,我可以正常地完成所有操作.所以节省一些时间:
是的我发布到正确的URL
是的我传递了有效的access_token
是的我在证明中使用相同的access_token,就像我在请求中一样
是的,我的appsecret很好,并且有效
使用示例
dynamic results = client.Post("/" + model.PostAsId + "/feed", new { message = model.Message, appsecret_proof = FaceBookSecret(postAs.AuthToken, AppSecret) });
我认为它可能与编码或其他东西有关,但说实话,我只是不知道.
我也在使用Facebook .net SDK,但这在文档中没有多少,并且似乎没有涉及与自动化,服务器端操作等有关的任何事情.
谢谢
我在Facebook上成功使用了以下内容
using System.Security.Cryptography; using System.Text; internal static string FaceBookSecret(string content, string key) { byte[] keyBytes = Encoding.UTF8.GetBytes(key); byte[] messageBytes = Encoding.UTF8.GetBytes(content); byte[] hash; using (HMACSHA256 hmacsha256 = new HMACSHA256(keyBytes)) { hash = hmacsha256.ComputeHash(messageBytes); } StringBuilder sbHash = new StringBuilder(); for (int i = 0; i < hash.Length; i++) { sbHash.Append(hash[i].ToString("x2")); } return sbHash.ToString(); }