I\'m using Node.js:
var s = \'Who\\\'s that girl?\';
var url = \'http://graph.facebook.com/?text=\' + encodeURIComponent(s);
request(url, POST, ...)
Had the same problem, encodeURIComponent didn't encode single quote. The trick is to do the replacement of ' with %27, after the encoding:
var trackArtistTitle = encodeURIComponent("Johnny Vegas - Who's Ready Fo'r Ice Cre'am")
// result: Johnny%20Vegas%20-%20Who's%20Ready%20Fo'r%20Ice%20Cre'am
trackArtistTitle = trackArtistTitle.replace(/'/g, '%27')
// result: Johnny%20Vegas%20-%20Who%27s%20Ready%20Fo%27r%20Ice%20Cre%27am
This way, trackArtistTitle will be properly decoded on server i.e. with PHP using urldecode().
You can encode the single quote as specified in this link http://www.w3schools.com/TAGS/ref_urlencode.asp
I know this doesn't address the OP's question, but for those coming here with OData Query related questions, note that the escape character is yet another single quote.
unescapedValue.replace(/'/g, '\'\'')
This assumes you have already performed an encodeURIComponent(unescapedValue)
on your string
Source: https://stackoverflow.com/a/4483742/2831961
I'm doing a similar thing (also with Node.js) and first tried using JavaScript's built-in escape() function, but it didn't really work.
Here's how I ended up getting search to work. It might just be a fluke:
function doMySearch(showTitle) {
showTitle = escapeShowTitle(showTitle)
var url = "http://graph.facebook.com/search?q=" + showTitle + "&type=page"
doSomethingWith(url)
}
function escapeShowTitle(title) {
title = title.replace(/'/g, "")
title = escape(title)
return title
}
doMySearch("America's Funniest home Videos")