Consider that a user visits an online news-website (nytimes, bbc, etc) and shares a story on facebook or twitter by commenting 'good' or 'bad' about it. My question is that, can news-websites (in this case nytimes, bbc, etc) control sharing the story by notify the user? If yes how they could do it? To further illustrate the problem, I want to update/cutomize FB.ui with ': ' in the following code. I don't know work around with this.
FB.ui(
{
method: 'share',
href: 'https://developers.facebook.com/docs/',
name: 'something here',
link: 'http://www.example.com/' + username,
caption: 'Contributions to the open-source world.',
<comment> : <'disabled'>
},
function(response) {
if (response && !response.error_code) {
alert('Posting completed.');
} else {
alert('Error while posting.');
}
}
);
Related
I have a simple facebook app, when I click a button with javascript function, I show me Post was successful! Action ID: 685335521499641, but not appear on the timeline. Also, when I go to Open Graph -> Stories for check, my meta tags is not functioning right, only the image if I change it. I get the POST code from Get Code with some change on it.
I read many comments, but nothing for my issue. So how can I make it right ?
The function is:
FB.api('/me/the_name:action_type', 'post', {
photo: "http://samples.ogp.me/XXXXXXXXXXXXXXXX",
image: "http://path_to_my_image.jpg",
title: "The sample photo",
description: "Just for test !!!",
},
function(response) {
var msg = 'Error occured';
if (!response || response.error) {
if (response.error) {
console.log(response.error);
msg += "\n\nType: "+response.error.type+"\n\nMessage:"+response.error.message;
}
alert(msg);
}
else {
alert('Post was successful! Action ID: ' + response.id);
}
}
);
The case may be that, you have not submitted the actions for the approval yet.
But you can check the story in the Activity log in your timeline. Or, directly with this url: https://www.facebook.com/me/activity/RESPONSE_ID
Once approved, the stories will appear in the news feed.
If someone have the same issue like mine, think I success, it's work for me for now.
So first generate new own object with https://developers.facebook.com/tools/object-browser , with correct App: and Object Owner:, mine was http://samples.ogp.me/XXXXXXXXXXXXXXXX (from Get Code). In there put only the URL (may be and title), where the meta tags are, it will get the meta tags for this URL.
So it will be 1st version.
FB.api('/me/the_name:action_type',
'post',
{
photo: "http://The_URL_with meta_tags",
image: "http://path_to_my_image.jpg",
title: "The simple photo",
description: "Just for test !!!",
},
function(response) {
... see above ...
}
});
2nd version: Allow the User Messages and User Generated Photos if will want big image and comment.
FB.api('/me/the_name:action_type?image[0][url]=http://path_to_my_image.jpg&image[0][user_generated]=true',
'post',
{
photo: "http://The_URL_with meta_tags",
message: "a simple message will appear above the image" ,
},
function(response) {
... see above ...
}
});
I don't know this is the right way, but hope to help if someone have the same issue, it will be for a guide. (if is OK go for submit in Review Status)
I want publish a post on my friend's wall via Facebook Api in Javascript, but this code don't run correctly when I insert in "FB.api" the "privacy". Can someone help me?
Thank you.
var privacy = {value: 'CUSTOM', friends: 'SOME_FRIENDS', allow: '{UID}'};
var privacy2 = JSON.stringify(privacy);
FB.api("/{UID}/feed", 'post', {
message: 'Message',
privacy: privacy2,
}, function(response) {
if (!response || response.error) {
alert(response.error);
} else {
alert('Message sent!');
}
}
);
Change the privacy JSON to include quotes around your keys as well:
var privacy={"value":"CUSTOM", "friends": "SOME_FRIENDS", "allow":"{UID}"};
FB.api("/{UID}/feed", 'post', {
message: 'Message',
privacy: privacy,
}, function(response) {
if (!response || response.error) {
alert(response.error);
} else {
alert('Message sent!');
}
}
);
However, it appears that you cannot post private messages to another user's wall. From the privacy settings page on Facebook:
Note: The privacy parameter only applies for posts to the user's own
timeline and is ultimately governed by the privacy ceiling a user has
configured for an app. It does not apply to posts made by an app on
behalf of a user to another user's timelines or to Pages, events, or
groups. In those cases, such posts are viewable by anyone who can see
the timeline or content in the group or event.
This appears to be why you are getting an OAuth error.
I would like to see best way of posting to Facebook from a HTML 5 game I will need to pull data from my javascript file to post to facebook I tryed adding.
FB.init({
appId: "309749382423000",
status: true,
cookie: true
});
function postToFeed() {
// calling the API ...
var obj = {
method: 'feed',
link: 'https://google.com/',
picture: 'http://google.com',
name: ' Run!',
caption: 'I just got a highscore of' + points2,
description: 'Try to beat my score!.'
};
function callback(response) {
document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
}
FB.ui(obj, callback);
}
This was added to my index file and it will not pull the var points2 that changes each time you play the game so would like some help with trying to add Post to facebook in html5 canvus
EDIT: wanted to post the full code The post to facebook works but the game is HTML5 so the javscript file keeps running in the game and the code above is in my index file that does not loop so it loads but will not run pull the "points2" var in to the facebook code. So real question would be how to add facebook post to canvus HTML5 game.
Assuming the user is already authenticated with your app use:
FB.getLoginStatus( function ( response ) {
if ( response.authResponse ) {
FB.api(
'/me/feed',
'post',
{
message: '',
name: 'Run!',
caption: 'I just got a highscore of ' + points2,
description: 'Try to beat my score!.',
link: 'https://google.com/',
picture: 'https://google.com/pic.png'
},
function ( response ) {
if ( response.id ) {
//success
} else {
//failure
};
}
);
};
} );
I'm attempting to use the Facebook Javascript SDK to post to an authenticated user's friend's wall. I get what appears to be a valid post ID in the response but the post does not appear on Facebook, and when I use the FB Graph API explorer to view the post, it simply returns false.
I'm using the FB login button with "publish_stream" permission for authentication and have a test FB app set up to get a valid App ID. I'm using the following code to post to the user's friend's wall:
FB.api('/[USER_ID]/feed', 'post', {
message: 'Testing the Facebook JavaScript API',
link: 'http://developers.facebook.com'
}, function(response) {
if (!response || response.error) {
console.log('Error occured');
} else {
console.log('Post ID: ' + response.id);
console.dir(response);
}
});
It works as expected when I replace [USER_ID] with 'me' - I can see the post on my FB timeline. However, when I use one of my friends' user IDs, I get a post ID response, but the post does not appear anywhere on their feed. Thoughts?
Here's my login button, too:
<fb:login-button show-faces="false" width="200" scope="publish_stream,publish_actions" perms="publish_stream"></fb:login-button>
I had the same problem. I worked on it like crazy for 5 hours. And actually, I think there is no problem. The only thing is that the posts on other's walls can arrive few hours later.
If anyone has the same problem, at least wait for a few hours before completely changing your code and turning crazy.
You can't post to a friend's wall
I was able to resolve this issue by creating an entirely new FB App from scratch, after which point the above code worked, which led me to think the issue must be in the configuration of my previous Facebook app. The only major difference I found was in App > Settings > Basic > Website > Site URL, I had entered the domain for my app and not the full path to the app page itself. So, you can indeed dynamically publish a post to the authenticated user's friend's wall.
here is with javascript sdk and facebbok c# sdk:
function fb_publish() {
FB.ui(
{
method: 'stream.publish',
message: 'Message here.',
attachment: {
name: 'Name here',
caption: 'Caption here.',
description: (
'description here'
),
href: 'url here'
},
action_links: [
{ text: 'Code', href: 'action url here' }
],
user_prompt_message: 'Personal message here'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
}
and
var client = new FacebookClient("my_access_token");
dynamic parameters = new ExpandoObject();
parameters.message = "Check out this funny article";
parameters.link = "http://www.example.com/article.html";
parameters.picture = "http://www.example.com/article-thumbnail.jpg";
parameters.name = "Article Title";
parameters.caption = "Caption for the link";
parameters.description = "Longer description of the link";
parameters.actions = new {
name = "View on Zombo",
link = "http://www.zombo.com",
};
parameters.privacy = new {
value = "ALL_FRIENDS",
};
parameters.targeting = new {
countries = "US",
regions = "6,53",
locales = "6",
};
dynamic result = client.Post("me/feed", parameters);
and would you please mark it as answered if it helps :)
Working on a project that has a website and a Facebook page. They both reference the same SWF file and JS code that the SWF file uses to interact with the website/Facebook.
The custom Javascript action, which invokes the FB.ui() method for sharing, works so much in that the dialog/popup appears, however Facebook results with an error ("An error occurred. Please try again later."). I get this error in all browsers.
Using a stream.share method works fine, however the stream.publish is giving me grief on the website. What's notable is that the exact same code works within Facebook.
I am loading the FBJS SDK through the same methods on both sites (The Facebook page is an iframe that's hosted on the same server) and also loading the scripts for the pages in the same order.
function connectFacebook(score) {
// No score, share link
if ( score == 0 ) {
FB.ui({
method: 'stream.share',
u: 'http://www.example.com/'
});
// Has score, publish to wall
} else {
FB.ui({
method: 'stream.publish',
message: 'I scored '+score+' at Game!',
attachment: {
name: 'Game',
caption: 'Game caption',
description: 'I scored '+score+'! Play and share to win the prize pack!',
href: 'http://www.example.com/'
},
action_links: [
{ text: 'Game', href: 'http://www.example.com/' }
],
user_message_prompt: 'Tell your friends about Game'
},
function(response) {
if ( response && response.post_id ) {
//alert( 'Post was published.' );
} else {
//alert( 'Post wasn\'t published.' );
}
});
}
}
I found out what the error was. When connecting to the FBJS SDK on the website, I had a Page ID entered instead of an App ID.