我很难为我的应用程序的两个用户找到共同的朋友,他们不是朋友。
根据all_mutual_friends权限,我需要与appsecret_proof参数一起发出请求。
我使用这个GET调用生成了app_access_token:
GET /oauth/access_token
?client_id={app-id}
&client_secret={app-secret}
&grant_type=client_credentials我已经三次检查了app_id和app_secret,它们是正确的。我是通过在appsecret_proof中使用app_secret对app_access_token进行散列处理来生成app_secret的。
现在,当我请求共同的朋友(发送appsecret_proof作为查询参数)时,它会响应如下:
"Invalid appsecret_proof provided in the API argument" 用GraphMethodException。最初的请求(没有appsecret_proof)对于朋友用户来说是很好的。这里有指点吗?
下面是我用来生成appsecret_proof的java代码:
public static String hashMac(String text, String secretKey)
throws SignatureException {
try {
Key sk = new SecretKeySpec(secretKey.getBytes(), HASH_ALGORITHM);
Mac mac = Mac.getInstance(sk.getAlgorithm());
mac.init(sk);
final byte[] hmac = mac.doFinal(text.getBytes());
return toHexString(hmac);
} catch (NoSuchAlgorithmException e1) {// throw an exception or pick a different encryption method
throw new SignatureException(
"error building signature, no such algorithm in device "
+ HASH_ALGORITHM);
} catch (InvalidKeyException e) {
throw new SignatureException(
"error building signature, invalid key " + HASH_ALGORITHM);
}
}
private static final String HASH_ALGORITHM = "HmacSHA256";
public static String toHexString(byte[] bytes) {
StringBuilder sb = new StringBuilder(bytes.length * 2);
Formatter formatter = new Formatter(sb);
for (byte b : bytes) {
formatter.format("%02x", b);
}
return sb.toString();
}我的服务器是基于python的。
发布于 2016-12-16 16:32:24
我找到了共同的朋友。我使用app_access_token来生成appsecret_proof,但是需要使用会话用户的access_token来生成appsecret_proof。显然,Facebook并没有对此进行记录。
https://stackoverflow.com/questions/41123463
复制相似问题