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
Related
I'm trying to implement the LinkedIn share API an I can't figure this one out, since the reply doesn't really tell what's going on.
I've implemented this simple code on my website
<script type="text/javascript" src="//platform.linkedin.com/in.js">
api_key: xxx
authorize: true
lang: de_DE
</script>
<script type="text/javascript">
// Handle the successful return from the API call
function onSuccess(data) {
console.log(data);
}
// Handle an error response from the API call
function onError(error) {
console.log(error);
}
function shareToLinkedIn(){
var payload = {
"content": {
"title": "Test title",
"description": "test description",
"submitted-url": "http://www.someurl.com",
"submitted-image-url": "http://someurl.com/somepic.png"
},
"visibility": {
"code": "connections-only"
}
};
IN.API.Raw("/people/~/shares?format=json")
.method("POST")
.body(JSON.stringify(payload))
.result(onSuccess)
.error(onError);
}
</script>
I'm calling this function via an onClick-event:
<a id="linkedin" href="#"onClick="shareToLinkedIn()"><i class="fa fa-linkedin-square" aria-hidden="true"></i> LinkedIn Test</a></li>
But all I'm getting is the following response: Object {errorCode: 0, message: "Invalid arguments: {S_400_BAD_REQUEST=Bad request}", requestId: "4JVTZJFVF1", status: 400, timestamp: 1467381898243}
Answer to this: You need to implement a login button on your site as well, it's not enough just to be logged in to the LinkedIn-Site.
So, on the site where you "share app" is implemented, add:
<script type="in/Login"></script>
After that, click the button, authorize the app and it should work.
You know, you can actually solve this problem without using the share plugin at all. In fact, just look at the LinkedIn Developers Homepage: "Share on LinkedIn" link. It no longer goes to the old LinkedIn documentation, which has broken styles, broken js, broken HTML, and missing images. It redirects to the Microsoft LinkedIn Share URL Documentation. If the LinkedIn share plugin isn't deprecated, it's certainly no its way there!
You can ditch the LinkedIn Share Plugin altogether. All you need, according to the Microsoft LinkedIn documentation, is the following...
https://www.linkedin.com/sharing/share-offsite/?url={url}
Wish you knew about these URLs changing and evolving without having to track them down yourself? I maintain a project on GitHub to do just that. Check us out! Social Share URLs
The notification is received but without the message.
Any idea why? Did facebook removed messages even that it's in the dev doc?
function newInvite(){
FB.ui({
method: 'apprequests',
title: 'Invite friends to play',
message: 'Come to play.',
new_style_message: true, // added this after a search but doesnt work either
filters: ['app_non_users']
});
}
https://developers.facebook.com/docs/games/services/gamerequests#dialogparameters:
message: A plain-text message to be sent as part of the request. This text will surface in the App Center view of the request, but not on the notification jewel
So yes, if you are talking about the notification jewel (the little globe symbol in the top bar in the web UI), this is supposed to work this way - there it will only show a text given by Facebook, “Foobar send you a request on Appname” or something like that.
Only the detailed App Center view under https://www.facebook.com/games/activity is supposed to show the message the user sending the request typed in.
I am trying to build a Chrome extension and I want to get all the posts that people posted on the user's wall specifically on his birthday.
I tried to call through Facebook Javascript SDK, but it is not returning the posts that are posted by my friends on the birthday.
FB.api(
'/me/feed',
'GET',
{},
function(response) {
// Insert your code here
}
);
Rather, it is returning all the birthday posts in one post like this:
{
"message": "Belated happy birthday bhaiii.....",
"created_time": "2015-10-19T00:02:02+0000",
"id": "578828115566706_848912165224965"
},
{
"story": "Ritwik Jain and 40 others wrote on your Timeline.",
"created_time": "2015-10-18T03:59:39+0000",
"id": "578828115566706_848604468589068"
},
How do I get each post individually?
Thanks in advance.
As you found out, the /me/feed endpoint is what you need to use - with the user_posts permission, of course. Facebook puts birthday posts together as it seems, but there is no other way to get the posts. Meaning, there is no way to get the birthday posts separately.
Endpoints for the user wall: https://developers.facebook.com/docs/graph-api/reference/v2.5/user/feed
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.
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.