Created
December 22, 2014 17:21
-
-
Save matb33/435b131e57447d853bde to your computer and use it in GitHub Desktop.
FacebookCollections help for Eduardo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<title>facebook</title> | |
</head> | |
<body> | |
<h1>Welcome to Meteor!</h1> | |
{{> loginButtons}} | |
{{> posts}} | |
</body> | |
<template name="posts"> | |
{{#each posts}} | |
{{message}} | |
{{/each}} | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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