Skip to content

Instantly share code, notes, and snippets.

@gregorynicholas
Created August 7, 2012 21:09
Show Gist options
  • Save gregorynicholas/3289383 to your computer and use it in GitHub Desktop.
Save gregorynicholas/3289383 to your computer and use it in GitHub Desktop.
How Pinterest invite facebook friends.
$(document).ready(function() {
function sendInvites(fb_ids, selector) {
var link_url = "http://pinterest.com/invited/?code=41165921502368484";
FB.ui({
method: "send",
to: fb_ids,
name: "Join Pinterest, the Virtual Pinboard",
description: "Pinterest lets you organize and share all the beautiful things you find on the web. People use pinboards to plan their weddings, decorate their homes, and organize their favorite recipes.",
picture: "http://media-cache0.pinterest.com//images/favicon_red_250.png",
link: link_url
}, function(response) {
if (!response){
selector.selectionCancelled();
return;
}
$.post("/invite/new/", {
fb_ids: fb_ids
}, function(data) {
if (data.status == "success") {
selector.afterSelection();
} else {
alert(data.message);
}
}, "json");
});
}
var friendSelectorElement = $("#facebook-friend-selector");
var friendData = [{"first_name": "Sandra", "last_name": "Aguilar", "user_id": null, "name": "Sandra Aguilar", "id_type": "uid", "id": "100001973482711", "photo_url": "https://graph.facebook.com/100001973482711/picture?type=square"}, {"first_name": "Natyk", "last_name": "Aguirre", "user_id": null, "name": "Natyk Aguirre", "id_type": "uid", "id": "634492080", "photo_url": "https://graph.facebook.com/634492080/picture?type=square"}, {"first_name": "Juan", "last_name": "Alzate", "user_id": null, "name": "Juan Guillermo Alzate", "id_type": "uid", "id": "749758612", "photo_url": "https://graph.facebook.com/749758612/picture?type=square"}, {"first_name": "Jorge", "last_name": "Andres", "user_id": null, "name": "Jorge Andres", "id_type": "uid", "id": "557855784", "photo_url": "https://graph.facebook.com/557855784/picture?type=square"}, {"first_name": "Jonathan", "last_name": "Andr\u00e9s", "user_id": null, "name": "Jonathan Andr\u00e9s", "id_type": "uid", "id": "686432679", "photo_url": "https://graph.facebook.com/686432679/picture?type=square"}];
new FriendSelector({
el: friendSelectorElement,
multiple: false,
friendList: friendData,
maxRetries: 10,
selectionMade: function(event, selectedUsers, selector) {
var fbIds = _.pluck(selectedUsers,"id");
sendInvites(fbIds, selector);
},
noAccess: function(event, selector) {
$("#facebook-connector-button").fadeIn(350);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment