Skip to content

Instantly share code, notes, and snippets.

@matb33
Created December 22, 2014 17:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matb33/435b131e57447d853bde to your computer and use it in GitHub Desktop.
Save matb33/435b131e57447d853bde to your computer and use it in GitHub Desktop.
FacebookCollections help for Eduardo
<head>
<title>facebook</title>
</head>
<body>
<h1>Welcome to Meteor!</h1>
{{> loginButtons}}
{{> posts}}
</body>
<template name="posts">
{{#each posts}}
{{message}}
{{/each}}
</template>
if (Meteor.isClient) {
Meteor.subscribe("userFacebookAccessToken");
Posts = null; // global so we can inspect in the browser console
Template.posts.helpers({
posts: function () {
// Unfortunately FacebookCollections does not handle the start-up process
// gracefully. You will need to wrap calls to FacebookCollections in
// try/catch to catch the exceptions it throws and guard your calls to
// find, fetch etc. The author of the package should have always returned
// a collection (an empty one instead of an error).
try {
Posts = FacebookCollections.getPosts("barackobama", 5);
} catch (e) {
console.warn(e);
}
return Posts && Posts.find && Posts.find();
}
});
}
if (Meteor.isServer) {
// The FacebookCollections package incorrectly assumes that the facebook
// accessToken is available to the client. This is simply not the case. In
// order for this package to work, we must publish the facebook accessToken
// to the client.
Meteor.publish("userFacebookAccessToken", function () {
if (this.userId) {
return Meteor.users.find({ _id: this.userId }, { fields: { 'services.facebook.accessToken': 1 } });
} else {
this.ready();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment