Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
191
rated 0 times [  196] [ 5]  / answers: 1 / hits: 120225  / 13 Years ago, sun, september 4, 2011, 12:00:00

I'm using Node.js:



var s = 'Who's that girl?';
var url = 'http://graph.facebook.com/?text=' + encodeURIComponent(s);

request(url, POST, ...)


This does not work! And Facebook cuts off my text...



Full code:



function postToFacebook(fbid, access_token, data, next){
var uri = 'https://graph.facebook.com/'+String(fbid)+'/feed?access_token='+access_token;
var uri += '&' + querystring.stringify(data);
request({
'method':'POST',
'uri': uri,
},function(err,response,body){
next();
});
};


app.get('/test',function(req,res){
var d = {
'name':'Who's that girl?',
'link': 'http://example.com',
'caption': 'some caption...',
'description': 'some description...',
'picture': 'http://i.imgur.com/CmlrM.png',
};
postToFacebook(req.user.fb.id, req.user.fb.accessToken, d);
res.send('done');
});


Facebook gets a blank post on the wall. No text shows. Nothing.



When I log my URI, it is this:



https://graph.facebook.com/1290502368/feed?access_token=2067022539347370|d7ae6f314515c918732eab36.1-1230602668|GtOJ-pi3ZBatd41tPvrHb0OIYyk&name=Who's%20that%20girl%3F&link=http%3A%2F%2Fexample.com&caption=some%20caption...&description=some%20description...&picture=http%3A%2F%2Fi.imgur.com%2FCmlrM.png


Obviously if you take a look at that URL, you see that the apostrophe is not being encoded correctly.


More From » string

 Answers
16

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)

[#90277] Thursday, September 1, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tomas

Total Points: 165
Total Questions: 111
Total Answers: 103

Location: Maldives
Member since Tue, Dec 21, 2021
2 Years ago
tomas questions
Thu, Jan 27, 22, 00:00, 2 Years ago
Mon, May 10, 21, 00:00, 3 Years ago
Tue, Jan 5, 21, 00:00, 3 Years ago
;