0

When using Facebook Graph API to send some notification to my users, it delivers scrambled to them, like so:

http://i.imgur.com/8ZvFT.png

Here is my code:

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)
    {
    }
}

Any idea?

EDIT:

I did a little reading about URL Encoding and this code solved my problem:

msg = HttpUtility.UrlEncode(msg);
4

1 に答える 1

0

これは、ページのエンコードが原因である可能性があります。正しくエンコードされていない場合、一部の文字はスクランブルされます。UTF-8 などを使用してみてください。私が考えることができる最高。

于 2012-11-14T20:40:22.457 に答える