Closed louisameline closed 10 years ago
there's no reason for you to have to do:
$.each(contacts, function(i, contact)){
var graph = new __fbgraph();
In your example, you already have access to __fbgraph. You should never have to do:
inside a loop.
Batch requests are get
requests with more params.
https://developers.facebook.com/docs/graph-api/making-multiple-requests/
Anything you can do with curl
you can do with fbgraph.
Sure but what I find unconvenient is that there is only one global accessToken variable in the module, or am I wrong ? Forgive me if I am, I have little time these days to investigate much. Ok, take this function :
function contact_post(contact) {
graph.setAccessToken(contact.accessToken);
graph.post("/feed", { message: "Message 1" }, function(err, res) {
graph.post("/feed", { message: "Message 2" }, function(err, res) {
});
});
}
Imagine that this function is called for contact1. While Facebook is taking some time to answer, imagine the function is called for contact2 : the access token variable is going to be overwritten with contact2's access token. When Facebook answers, the second call to graph.post() for contact1 is made, but it will fail because of the wrong access token. So that forces us to set the access token before every call, which is annoying.
That's why I prefer to create one fbgraph object per contact, using the require inside a loop (I know, I don't like that either, I'd rather have a proper method). That way, each object represents a separate connection to Facebook and will not interfere with the others. And incidently, the credentials can be set once only. It seems more intuitive and all to me.
As for batch requests, I can't see how you handle them in fbgraph, can you give me an example ? If you mean that I can build the whole request myself, well sure, but isn't that the point of a library ? What I expect is this (quoted from a library similar to yours) :
FB.api('', 'post', {
batch: [
{ method: 'get', relative_url: '4' },
{ method: 'get', relative_url: 'me/friends?limit=50' }
]
});
Ok, forget the batch request thing sorry, I see your lib can do the same. Maybe just an example in the doc would be welcome, since it's the first thing I looked for in the readme and couldn't find an answer straight away. Thank you.
Cool, so:
Basically following the same idea as: https://developers.facebook.com/docs/javascript/reference/FB.api Libs that create specific methods are bound to fail if they're not consistently in sync with their endpoints. Trust me, you don't want to wait for a new fbgraph release just because facebook changed something.
Last -respectful- rant for today, about your lib tampering the /user_id/picture response in :
graph.get("/zuck/picture", function(err, res) {
console.log(res); // { image: true, location: "http://profile.ak.fb..." }
});
You are probably aware that people who do not want the facebook redirection may specify a redirect parameter set to 0 ? See https://developers.facebook.com/docs/graph-api/reference/user/picture/ So I think the lib should send the picture resource for this one, not home-made json. It's ok for an API to return anything other than JSON really.
Thank you
I'm going to be a pain in the ass, but for the sake of the debate I'll explain why I'm not a fan of your approach :
By tampering the results, I know you want to create consistency so we do not have to care about the format of what Facebook actually sends, and save us the hassle of writing specific code for it. But the result is, we can't fully trust Facebook's documentation anymore, according to which request we are making. Instead, we have to learn the schema of the json that your library sends back in these exceptional cases. In the end, instead of specific code for Facebook, we have to write specific code to adapt to your library's response. In this case, I feel like I lose more than I win, but that's just me. Thanks anyway for your work, it's appreciated.
Valid point but this was written a while a ago and while facebook's docs may have gotten better, I've learned not to trust them regarding backwards compatibility.
Also, you're not being a pain in the ass. You have strong opinions about how this should work. Sounds like a fork is in order.
I'm not sure about a fork, but thank you for your answers. Have a nice day Cris.
You too dude
Hello and thank you for the good work on this module.
A suggestion : it would be nice if we could require the module once at the beginning of our scripts instead of everytime we to open a connection to Facebook.
Unless I missed something, right now we have to write :
I'd rather do something like
Also, I see no support of the batch get requests, which is going to be a deal breaker for me. Thanks anyway :)