当使用 Facebook Graph API 向我的用户发送一些通知时,它会向他们发送乱码,如下所示:
这是我的代码:
public void sendFBNotificationByUserID(Guid userID, string msg, string url)
{
try
{
// Facebook information from the user
FacebookUser fbUser = getFacebookUserByUserID(userID);
using (WebClient wc = new WebClient())
{
// Retrieve "App Access Token" from Facebook
string appAccessToken = wc.DownloadString("https://graph.facebook.com/oauth/access_token?client_id=" + Global.fbAppID + "&client_secret=" + Global.fbAppSecret + "&grant_type=client_credentials");
// Create POST parameters
string POSTparam = "template=" + msg + "&href=" + url + "&" + appAccessToken;
// POST to Facebook Graph API to send notification
wc.UploadString("https://graph.facebook.com/" + fbUser.facebookID + "/notifications/", POSTparam);
}
}
catch (Exception)
{
}
}
任何的想法?
编辑:
我做了一些阅读URL Encoding
,这段代码解决了我的问题:
msg = HttpUtility.UrlEncode(msg);