我正在尝试使用 facebook graph api 向用户墙发布消息。 https://graph.facebook.com/me/feed
å、ä 或 ö 之类的字符会与 ���... 之类的符号一起显示不正确
我在请求中发送的所有相关参数(消息、名称、描述)周围使用了 apacheCommons StringEscapeUtils.encodeHtml。
def params = [
accessToken: getFacebookAccessToken(),
message: StringEscapeUtils.escapeHtml(deal.title),
pictureUrl: imageUrl,
name: StringEscapeUtils.escapeHtml(deal.title),
description: StringEscapeUtils.escapeHtml(deal.shortDescription),
actionLabel: StringEscapeUtils.escapeHtml(actionLabel),
actionUrl: actionUrl
]
def graph(path, params, method = GET, contentType = JSON) {
def http = null
http = new TrustAllHttpBuilder(ConfigurationHolder.config.facebook.graph.uri)
http.request( method, contentType) { req ->
uri.path = path
req.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES );
req.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout );
req.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, socketTimeout );
requestContentType = URLENC
body = params
response.success = { resp, obj ->
return obj
}
}
}
更改后,“名称”和“描述”在 facebook 中正确显示,但“消息”仍然无法正确呈现。
任何想法为什么“消息”没有正确显示?FB的处理方式不同吗?
谢谢
更新
在发送 JSON 请求的正文之前,我将参数调整为 URLEncoded 为 UTF-8。
def params = [
accessToken: getFacebookAccessToken(),
message: URLEncoder.encode(deal.title,"UTF-8"),
pictureUrl: imageUrl,
name: URLEncoder.encode(deal.title,"UTF-8"),
description: URLEncoder.encode(deal.shortDescription,"UTF-8"),
actionLabel: URLEncoder.encode(actionLabel,"UTF-8"),
actionUrl: actionUrl
]
请求:
14:49:13 DEBUG [FacebookService] body: Message: Tommy+%C3%80%C3%84%C4%87%C3%95,Name: Tommy+%C3%80%C3%84%C4%87%C3%95,Description: %C3%80%C3%84%C4%87%C3%95%C3%80%C3%84%C4%87%C3%95,Caption: ,Action Label: TEST,ActionUrl: http://www.mytest.com
14:49:51 DEBUG [FacebookService] Calling facebook graph API https://graph.facebook.com/me/feed
14:49:51 DEBUG [TrustAllHttpBuilder] POST https://graph.facebook.com/me/feed
14:49:52 DEBUG [headers] >> POST /me/feed HTTP/1.1
14:49:52 DEBUG [headers] >> Accept: application/json, application/javascript, text/javascript
14:49:52 DEBUG [headers] >> Content-Length: 475
14:49:52 DEBUG [headers] >> Content-Type: application/x-www-form-urlencoded; charset=windows-1252
14:49:52 DEBUG [headers] >> Host: graph.facebook.com
14:49:52 DEBUG [headers] >> Connection: Keep-Alive
14:49:53 DEBUG [headers] << HTTP/1.1 200 OK
14:49:53 DEBUG [headers] << Access-Control-Allow-Origin: *
14:49:53 DEBUG [headers] << Cache-Control: private, no-cache, no-store, must-revalidate
14:49:53 DEBUG [headers] << Content-Type: application/json
14:49:53 DEBUG [headers] << Expires: Sat, 01 Jan 2000 00:00:00 GMT
14:49:53 DEBUG [headers] << Pragma: no-cache
14:49:53 DEBUG [headers] << X-FB-Rev:
14:49:53 DEBUG [headers] << X-FB-Debug:
14:49:53 DEBUG [headers] << Date: Fri, 05 Oct 2012 13:49:52 GMT
14:49:53 DEBUG [headers] << Connection: keep-alive
14:49:53 DEBUG [headers] << Content-Length: 40
FB 中的结果(不工作):