Facebook js api: share a post to a friend's wall - javascript

i really hope, someone can point me into the right direction. I am ordered to write a drawing game for facebook. The concept is, the one, applying for a win, references a friend for the prize (the player won't win anything, just his friend).
The customer want's a Post on both Walls/Timelines. AFAIK it's not possible to post on the friend's wall. Right now i am as far, that the App posts on the wall, of whom is playing.
Is it possible to share this Post to his friend without any Dialog or represent to the friend, that he is applied for a prize?
The customer wants that this doesn't use any share/feed dialog.
Thanks in advance

After the second day of digging in i came to a solution. As the Open Graph Api mentions, the keyword is tagging BUT, the META tags mentioned in the documentation didn't work for me in any way.
I came up to use an Page ID for the place field and used the friends ID as value for the tags field. Once the friend is tagged with the post, he will see the same post on his own timeline.
Here's a snippet:
facebook.api('/me/feed', 'POST', {
'message' : userdata.name + ' hat für ' + frienddata.name + ' einen ' + $('span.buggyname').html() + '...',
'picture' : 'some picture URL',
'link' : 'URL to see game result',
'name' : 'our awesome game',
'place' : 'pageid of customer',
'tags' : frienddata.id
}, function(response){
console.log(response);
});

Related

FB.ui sharing app result help needed

I have a javascript game app added as a page tab, it is a memory game which counts the number of turns needed to solve the puzzle. can anyone help me how to share the variable which holds the result with FB.ui share dialog?
FB.ui({
method: 'share',
message: 'some message',
link: 'MY LINK ',
picture: 'some pic',
caption: 'Reference Documentation',
description: 'you solved the puzzle in' + this.Moves + 'turns', },
The app with the id is published on the page if that helps.
The Share Dialog is for sharing URLs only, and it takes the OG data from that URL. Earlier it was possible to use those parameters in your code with the Feed Dialog, but they are deprecated now: https://developers.facebook.com/docs/sharing/reference/feed-dialog
You could create a unique URL for it and include the score in the OG data of that URL, that´s the proper way as of now, afaik.

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

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.

Facebook - FB.UI feed and share dialog

I have some trouble with the Facebook FB.UI - Feed and Sare dialog.
I need to send the page of the website to a friend, im using the FB.UI Javascript API. According to the facebook documentation they said you have to use the "from and to" parameter. But when i use the "from and to" parameters it doesn't work. When i delete these parameters it works fine, but i cant post to a friends wall for sure.
I've been looking for a while, and have try'd the following steps:
Does the user have enabled the right settings to post on his timeline (check)
Does the user have liked the facebook page (check)
Am i logged in (check)
This is the link to the documentation: Feed and Share Dialogs
This is my code:
PS: I get the alert what is saying: "Post was published" but it doesn't show up on facebook.
function share()
{
FB.ui({
method: 'feed',
name: 'The name',
link: 'The URL',
from: '100001738814056',
to: '100003105898115',
caption: 'An example caption',
}, function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
}
edit: I've got some more information about my problem, and i guess i found the problem..
If you take a look at this image you'll see a row with: "Feed" and one with "?api_key=". If im taking a look at the URL of feed i guess it misses the get api key, not sure if iam correct
The image link
We'll after a day of searching.. i know the solution.
If you create an app in Facebook, the mode of the app is " in sandbox mode ", when you turn the sandbox mode off you can post to facebook while tagging a friend!
So my problem is solved.

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