FB.ui({ method: 'feed',
name: name,
link: 'http://apps.facebook.com/my-app/',
picture: 'app-picture',
caption: 'this is only for me',
privacy: { value: 'SELF' }},
function(response) {
if (response && response.post_id) {
// Post was published
alert('Post was published.');
} else {
alert('Post was not published.');
}
return true;
}
);
not working
resolved:
FB.api('/me/feed', 'post', {
message: 'message',
name: 'name test',
caption: 'caption',
privacy: { 'value':'CUSTOM','friends':'SELF'} },
function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
Related
I want to post into a facebook page with image. I got this error (#200) Subject does not have permission to post photos on this page. Please help me. I don't know what to do.
FB.login(function(auth) {
if (auth.status === 'connected') {
FB.api('/me/accounts', 'get', function(response) {
response.data.forEach(function(item) {
if (item.id == "<page_id>") {
post_to_page(item.access_token);
}
});
});
}
}, {scope: 'manage_pages, publish_pages, publish_actions'});
function post_to_page(access_token_data) {
var data = {
url: 'https://i.imgur.com/iXEkIJf.jpg'
}
FB.api('/<page_id>/photos', 'post', data, function(response) {
if (!response || response.error) {
console.log(response.error);
} else {
console.log(response.id);
}
});
}
I got it already and it works!
var FACEBOOK = {};
FACEBOOK.post_to_page = function() {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
post_to_page(FB_PAGE_ACCESS_TOKEN);
} else {
FB.login(function(response) {
post_to_page(FB_PAGE_ACCESS_TOKEN);
}, {scope: 'manage_pages, publish_pages, publish_actions'});
}
});
}
function post_to_page(access_token_data) {
var body = 'Facebook Error: (#200) Subject does not have permission to post photos on this page.';
var data = {
message: body,
access_token: access_token_data,
url: '<image_url>'
}
FB.api('/<fb_page_id>/photos', 'post', data, function(response) {
if (!response || response.error) {
console.log(response.error);
} else {
console.log(response.id);
}
});
}
I have been using Graph API along with javascript facebook sdk to make posts on users wall. The code looks like this
function graphStreamPublish(){
showLoader(true);
FB.api('/me/feed', 'post',
{
message : "Sample Message",
link : 'link url',
picture : 'image url',
name : 'app name',
description : 'Test stuff'
},
function(response) {
showLoader(false);
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
}
Can this piece of code be used to post on users timeline as well or is there something else I need to do?
The following code works. ( Notice the 'publish_actions' permission used at the end).
FB.login(function(response) {
// handle the response
if (response.status === 'connected') {// Logged into your app and Facebook.
FB.api('/me/feed', 'post',
{
message : "Sample Message",
name : 'app name',
description : 'Test stuff'
},
function(response) {
if (!response || response.error) {
alert(response.error);
} else {
alert('Post ID: ' + response.id);
}
});
}
}, {scope: 'public_profile,email,publish_actions'} );
Years ago, you could use field TO with user id, nowadays you cant post to users timeline, but you can use TO field with an ID, for posting on groups, events or pages .
Im trying to upload a photo to one of my albums on facebook, with the below code, but no upload and now error?
What are I missing?
I have a album thats called Loggfoton where I want the photos to end up, or if there is no album at all, then that one is created.
function uploadphoto(){
var imgURL =
"http://www.mydomain.se/armani1.jpg";
FB.api('/me/photos', 'post', {
message: 'photo description',
access_token: accessToken,
url: imgURL
}, function (response) {
if (!response || response.error) {
alert('Error occured:' + response);
} else {
alert('Post ID: ' + response.id);
}
}); }
Any input really appeciated!
Thanks!
Use "/album_id/photos" as url:
function uploadphoto(){
var imgURL = "http://www.mydomain.se/armani1.jpg";
FB.api('/album_id/photos', 'post', {
message:'photo description',
url:imgURL
}, function(response){
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
}
Hope it helps
How can I call a function, when Facebook has been authourized??
FB.ui({
client_id: '9999999999999',
method: 'oauth',
scope: 'email, user_about_me, user_likes',
response_type: 'token'
});
???
FB.Ui has a callback function.
FB.ui(
{
method: 'feed',
name: 'Facebook Dialogs',
link: 'https://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
Facebook state that you should not use the OAuth Dialog directly from the Javascript SDK so here's an example using FB.Login with a callback for when the user has accepted/denied the permissions.
FB.login(function(response)
{
if (response.authResponse)
{
// user has granted permissions
}
else
{
// user did not grant permissions
}
},
{
scope: 'email, user_about_me, user_likes'
}
);
Hi i am trying to post image to friends wall from my FB app. I have this code, but dont know how to attach image to the post. It only posts text. Anybody has working example ? Or where i have error ? thanks.
FULL PATH TO IMAGE HERE - replaced with path to image
FULL PATH TO MY FB APP HERE - replace with path to fb app.
FB.ui(
{
target_id: '100000505490012',
method: 'stream.publish',
message: 'Just Testing!!!.',
attachment: {
name: 'test name',
caption: 'Caption here.',
description: (
'description here'
),
href: 'http://facebook.com/mysite'
},
media: {
type: 'image',
src: 'FULL PATH TO IMAGE HERE',
href:'FULL PATH TO MY FB APP HERE'
},
action_links: [
{ text: 'Code', href: 'FULL PATH TO MY FB APP HERE' }
],
user_prompt_message: 'Personal message here'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
The media attribute actually goes inside the attachment attribute.
FB.ui({
target_id: '100000505490012',
method: 'stream.publish',
message: 'Just Testing!!!.',
attachment: {
name: 'test name',
caption: 'Caption here.',
description: 'description here',
href: 'http://facebook.com/mysite',
media: [{ 'type': 'image', 'src': 'FULL PATH TO IMAGE HERE', 'href':'FULL PATH TO MY FB APP HERE'}]
},
action_links: [{ text: 'Code', href: 'FULL PATH TO MY FB APP HERE' }],
user_prompt_message: 'Personal message here'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);