How to sent a website url as link to multiple Facebook Friends? - javascript

I am setting up a website. I want users to invite Facebook friends to look at the page the users can make on my website. So i'm trying to get it done. But i think the FB Api is not set up to do what i want to do. I think it is to prevent from spamming, but i really like to know if it can be done or not.
This is what i have so far. Users can login with FB and i present a decent list of FB friends.
Each friend has a checkbox. When a user submits the form, i collect all the checked friends id's:
var sendUIDs = '';
var mfsForm = document.getElementById('mfsForm');
for (var i = 0; i < mfsForm.friends.length; i++) {
if (mfsForm.friends[i].checked) {
sendUIDs += mfsForm.friends[i].value + ',';
}
}
While i was trying, i came up with this "sollution" for sending all the friends the same invite:
FB.ui({
method: 'apprequests',
to: sendUIDs,
message: "Hey come on look at my site",
data: "mywebsite.com/userlink"
});
Looking great I thought. Exactly what i wanted... i thought.
Unfortunately this is only used for games? First of all i could not find the invite. It was there, but it seems to disappear. Then i found out it was in the App/Games/Activity tab.
I managed to get the notification in the "notification" tab by adding a Canvas to my FB App. Almost there i thought. Well, not exactly... I want the friends to visit my page by the given data link and not some weird ?number.
So i gave up this path and tried the other way and came up with this:
for (var i = 0; i < mfsForm.friends.length; i++) {
if (mfsForm.friends[i].checked) {
var uid = mfsForm.friends[i].value;
FB.ui({
to : uid,
method: 'send',
name: 'Visit my page',
link: 'mywebsite.com/userlink'
});
}
}
This works more or less, but produces a popup for every friend with an empty message box. Not very friendly and, well... stupid :)
I also tried the former setup, but instead of "apprequests" i used this:
FB.ui({
method: 'send',
to: sendUIDs,
message: "Hey come on look at my site",
data: "mywebsite.com/userlink"
});
where i tried this for the sendUIDs: [1, 2, ...] and just 1, 2, ...
No luck, because FB only processed one name.
I would think there must be a way to get the job done, but for now i am very confused how to proceed. I would think FB could make things a bit more easy?

The Send and Share Dialogs are built for this (sharing a Website URL on a wall or send it to friends in a PM), just let him choose the friends in the popup. That way, you don´t even need to authorize the user, and you can´t get ALL friends anyway (only those who authorized the app too).
About the message parameter: You are not allowed to prefill the message, it has to be 100% user generated. See the Platform Policy: https://developers.facebook.com/policy
2.3 Ensure that all content in the user message parameter is entered by the user. Don’t pre-fill. This includes posts, messages, comments,
and captions.
The FB.ui Dialogs ignore the message parameter anyway.

Related

Implement a window to log in LinkedIn in MVC 5

I'm working in an mvc5 application where users have their own profiles, there should be a button which would open a pop-up window so that an individual user logs into LinkedIn as to sync his/her LinkedIn profile picture with our site's.
I don't think it can be implemented with modals because there's page navigation involved, so I thought about what I stated previously: a pop-up, is there a way to do this via javascript? Like, opening a pop-up and expecting a response to determine if the user logged in. If there is a better way, any info would be greately appreciated, my aim is to be able to sync the profile picture without having the user to get redirected to linked in from their profile view, I want them to change it from there and not leave the view. Is it possible to do so?
EDIT: To clarify, getting the image URL is not a problem, what I need to do is get the url from the profile window, which comes from the popup window.
You should have a look at their API it is well documented. You'll need additional permissions to retrieve the full profile. LinkedIn Profile API
I ended up using the Javascript SDK:
$('#btnSyncLinkedInPicture').on('click',
function () {
var myID = 3;
IN.User.authorize(function () {
IN.API.Raw("/people/~:(picture-url)").result(function (data) {
$.ajax({
type: 'GET',
url: '/MyController/MyAction?pictureUrl= ' + data.pictureUrl + '&id=' + myID,
success: function (result) {
$('#imgProfilePicture').attr('src', result);
}
});
}).error(function () {
});
});
});
First, we authorize the user which will open a pop-up window so that we authenticate, the SDK will abstract us from the OAuth process. After authenticating, we may want to write a callback function, in which we can already perform REST calls via the SDK methods (you can do it elsewhere as long as you have successfully authenticated).

Cant loop through users to send them individual message FB.ui()

I am looking for a way to send messages to multiple people without creating group chats and I have been working on this for two days now. I am trying to use a little hack where it loops through and ID list and basically takes values in an array and loops through them so one by one it sends a message. Basically, one ID sends message, then it loops back second ID sends message and so on until all parties have received a message. Here is my code so far
tl1.addEventListener("click", function() { //Send Message
try
{
var users = ['100008601850848', '100002242788752'];
for (var i = 0; i < users.length; i++)
{
FB.ui({
app_id: '1226220854077249',
method: 'SEND',
link: 'https://developers.facebook.com/apps/1226220854077249/roles/test-users/',
to: users[i]
});
}
}
catch(error)
{
console.log(error);
}
}, false);
Am I approaching this right? It does not send a message to all of them it only puts the first user in the field. All I am trying to do is make a loop that sends messages to one user then the next and so on. Basically sending it to multiple ID's but without creating groups as the FB.UI() does
There is only one way to use the send dialog, and if it creates a group chat then that´s what you have to live with. Right now you are trying to open several popups at once, which is a pretty ugly workaround - if it even works.

How to get Facebook user's friends' profile picture using Javascript SDK V2.0

I am creating a website using Facebook API V2.0 JavaScript SDK and I would like to display the profile pictures of the user's friends.
I have managed to display my profile picture using the graph API but I can't manage to get the ID of all my friends if I am logged in my app (I am an admin). If I have the ID, I'll be able to show their profile picture.
In the graph explorer, I have checked all permissions (User Data Permissions + Extended Permissions). I have noticed if I switch to API V1.0, I get friends permission which is exactly what I'd like.
Also, I have added a couple of permission to my app in Facebook developers > App details > App Center Listed Platforms > Configure app center permissions. (user_friends + friends_birthday + friends_religion_politics + friends_relationships + friends_relationship_details + friends_location + friends_photos + friends_about_me)
So far, my html looks like this :
<fb:login-button scope="public_profile,email,user_friends,read_friendlists" onlogin="checkLoginState();">
After loading the Facebook SDK, I have :
function getUserFriends() {
FB.api('me/friends?fields=first_name,gender,location,last_name', function (response) {
console.log('Got friends: ', response);
$("#friendslist").html('<img src="https://graph.facebook.com/'+ response.id+'/picture?type=large"/>');
});
}
However, the array which is suppose to contain all my friends info is empty (see image : http://www.screencast.com/t/W02GaOm3h)
If all you need is their image, this can be found in the "taggable_friends" scope. However, do note that this field is very limited (by design) and that you require additional review by Facebook in order to present it to the average user.
It contains:
A taggable id. This is an id with the express purpose of tagging; it cannot be used to identify the user or otherwise gather information from their profile.
A name. The user's first and last name.
A picture, with common related fields. Url, is_silhouette, height and width.
function getUserFriends() {
FB.api('me/taggable_friends', function (response) {
console.log('Got friends: ', response.data);
$("#friendslist").html('<img src="'+response.data[0].picture.data.url+'"/>');
// maybe an $.each as well
// var friendMarkup = '';
// $.each(response.data, function(e, v) {
// friendMarkup += '<img src="' + v.picture.data.url +'" alt="'+ v.name +' picture"/>';
// }
// $("#friendlist").html(friendMarkup);
});
}
Related reading:
https://developers.facebook.com/docs/graph-api/reference/v2.0/user/taggable_friends
https://developers.facebook.com/docs/opengraph/using-actions/v2.0 - Tagging friends and Mentioning friends sections
A disclaimer: I've been battling with this issue for several days without really being able to mention-tag. My submission to use taggable_friends as a comprehensive, navigatable list for the user was rejected and I speculate (speculation ho!) it was because I did no actual tagging. I'll get back to this in a few days when I've clarified and re-submitted my request for a review on Facebook.
-- Edit --
It would seem the reason my initial submission was rejected was because I was using a special development url and did not point out clearly enough why it was not enough to use the url set under settings. This time I clearly pointed out and explained this reasoning in both the general description of my submission and in the step-by-step notes. In summary, be exceptionally clear in your submission about everything; your reasoning as to why you need this permission, how they can access it, etc. Just to make sure it isn't missed if skim-read.
It seems like in V2.0, Friends permission have dissapeared :
Facebook graph api explorer doesn't show 'Friends Data Permission' tab
https://developers.facebook.com/docs/facebook-login/permissions/v2.0

Send a message to a friend, I wonder Javascript API

I am a developer from the Republic of Korea.
I am currently making Facebook and Twitter-based websites.
I want to use a JavaScript API that can send message to friends,
So I consulted the iframe Javascript API methods or using Facebook page looked as sending.
I wonder,
I use to send messages to friends as a Javascript API that provides a?
I do not know English well. So I used Google translator.
Please understand.
(Edited, fixed some grammar and rewording)
FB.api (path, "post", {
message: msg,
caption: "caption caption",
link: "http://www.naver.com",
description: "Description Description",
picture: "http://sstatic.naver.net/search/img3/h1_naver.gif",
tag: "Tag",
name: "name names",
access_token: accessToken
}, Function (response) {
if (! response | | response.error){
alert ("error");
}
else{
alert (response.id);
}
})
You want to send a message to a friend on Facebook, or post to the Facebook wall for all to see? I am going to assume sending a message to a friend on Facebook.
Manual
If you want to send a message to friends on Facebook using the JS SDK, follow these instructions: https://developers.facebook.com/docs/reference/dialogs/send/
This isn't automatic and will still show a dialog box for the user to confirm.
Automatic
If you wanted to do it in the background via the Graph API, you can't. Here is a link explaining it in further detail why you can't and other options you have: https://stackoverflow.com/a/4061298/540339

Facebook - Posting to a Group page

I am attempting to post on a group page using the FB JS API, basically the user selects the group they want to post onto, and it posts it to the wall.
i am doing:
FB.ui(
{
method: 'stream.publish',
from: myId,
to: groupID,
attachment: {
name: 'Post to a group Test,
href: 'http://www.test.com'
}
});
But when i try it, it says:
An invalid target was specified:
<(groupid)>. The target must be a
page, event, or user that the actor
can post on the wall of.
Thou, i know i can post on the group page, so i dont know why it says that.
And i am not talking about fan pages, i can post on them ok setting the from and to as the same thing (posting as an admin).
Is this possible? or am i just doing it wrong?..
Thanks,
Andrew
It seems that both stream.publish and feed methods are not supported for groups object so your best solution is to use (for example) the jQuery UI Dialog component with the fields you need to post to the group as inputs and on the submission use the FB.api method:
FB.api("/group_id/feed", 'post', { name: nameVar, link: linkVar }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
I'm not experienced, with the facebook API, but what is the value of the groupID variable? is it "(groupid)"?
If not, then it is a really unclear error message - and I wonder how the API knows that you tried to post on a group.
If so, then there you have it ;-) You should fill in a group id.
According to the documentations, Facebook groups are not mentioned in the list of possible targets to publish to. I filed a bug to hopefully get Facebook to address this:
http://developers.facebook.com/bugs/158247050931954

Categories