我正在尝试使用restfb api通过facebook应用程序向facebook用户发送通知。尝试发布此类通知时,会显示异常
"com.restfb.exception.FacebookGraphException: Received Facebook error response of type
GraphMethodException: Unsupported post request".
以下是我的代码:
FacebookType = facebookAppAccessToken.publish("user_id/notification?access_token=app_access_token"),
FacebookType.class, Parameter.with("template","send_notification"),
Parameter.with("href,"sample_link"));
请帮我解决这个问题。提前致谢
答案 0 :(得分:1)
public void sendNotification(String externalUserId, String message) {
AccessToken appAccessToken = new DefaultFacebookClient()
.obtainAppAccessToken(APP_KEY, APP_SECRET);
FacebookClient facebookClient = new DefaultFacebookClient(
appAccessToken.getAccessToken());
try {
facebookClient.publish(externalUserId
+ "/notifications", FacebookType.class,
Parameter.with("template", message));
} catch (FacebookOAuthException e) {
if (e.getErrorCode() == 200) {
//Not an app user
} else if (e.getErrorCode() == 100) {
//Message cannot be longer than 180 characters
}
}
}
正确处理错误代码。您可以根据自己的要求添加href和ref。 Here是参数的详细信息。