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
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'm creating an app to publish photos in Facebook. With my code I receive this error:
{"error":{"message":"(#324) Requires upload file","type":"OAuthException","code":324}}
I know that the login is ok....but after the upload give me this error...
Someone can help me please?
ciaopoint2.Globals.imagefinal = 'data:image/jpg;base64,'+canvas.toDataURL("image/jpg");
//Verifico lo Stato del Login
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
FB.api(
'/photos',
'POST',
{
message: 'CiaoPoint ti ringrazia',
source: ciaopoint2.Globals.imagefinal
},
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
}
else {
FB.login(function(response) {
if (response.authResponse) {
FB.api(
'/photos',
'POST',
{
message: 'CiaoPoint ti ringrazia',
source: ciaopoint2.Globals.imagefinal
},
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
}
else {
alert("Non puoi loggarti in Facebook");
}
}, {scope: 'email'});
}
});
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 .
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);
}
});
I am using facebook javascript SDK to post comment on facebook and using this code:
FB.init({
//appId: 'YOUR_APP_ID', cookie: true,
appId: '2697XXXXXXXXXX098', cookie: true,
status: true, xfbml: true
});
FB.ui({
method: 'feed',
name: 'MyComment',
link: 'http://www.facebook.com./',
picture: 'http://xyz.com/App_Shared/Images/logo.jpg',
caption: 'Comment caption',
description: 'comment description',
message: 'Join facebook.'
}, function (response) {
if (response && response.post_id) {
alert('Post was published.' + response.post_id);
} else {
alert('Post was not published.');
}
});
and now i want to delete this post by using the same type of js code.
I saved post_id in my database.
Can you provide me the code or any URL to do this.....
First of all you must give to access to you application and allow by user according to this URL
http://developers.facebook.com/docs/reference/api/permissions/
These permission you can use like this method
FB.login(function (response) {
if (response.authResponse) {
FB.api('/me', function (response) {
jQuery('#hdfUID1').val(response.id);
jQuery('#btnFBLoginTemp').click();
// FB.logout(function (response) {
// });
});
} else {
jQuery('#hdfUID1').val('');
}
}, { scope: 'email,user_photos,read_stream,publish_stream,offline_access' });
if user allow these permissions then you can delete comment from user's wall which was posted by your application by using "Anatoly Lubarsky" answer method....
FB.api(postId, 'delete', function(response) {
// callback here
});
should be very simple like:
FB.api(postId, 'delete', function(response) {
// callback here
});
hope this helps