How to include images in page post API - facebook

I keep getting this error message when am attaching images to page post
message: '(#10) Application does not have permission for this action'
but when am posting message only, it works fine
FB.api('PAGE_ID/feed', 'post', {
message: 'Message is here',
link: 'https://my_LINK.com',
"child_attachments": [
{
"link": "https://1.jpg",
"image_hash": "hash1",
"name": "Some Name",
"description": "Some description"
},
{
"link": "https://2.jpg",
"image_hash": "hash2",
"name": "Some Name",
"description": "Some description 2"
}]
}, function (res) {
if (!res || res.error) {
console.log(!res ? 'error occurred' : res.error);
return;
}
});

to add multi images to a post in facebook, it has to be done in 2 steps as per facebook
to upload image, refer to this and to make the post
function post_fb_ad(description, ad_images) {
attached_media = []
for (var adImg of ad_images) {
attached_media.push({ media_fbid: adImg.id })
}
FB.api('page_id/feed', 'post', {
message: description,
attached_media: attached_media,
access_token: EXD_ACCESS_TOKEN
}, function (res) {
if (!res || res.error) {
console.log(!res ? 'error occurred' : res.error);
return;
}
console.log('post id is ', res)
});
}

In order to publish to a page, you will need to use a page access token that has publish_pages permission which you may be missing.
You can quickly test the request using the Graph API Explorer tool.
You can also use the Access Token Debugger tool to test what permissions your access token has.
Also, note that publish_pages permission is reviewable and needs to be approved before you can use it with the general public. Prior to approval, you can only test it with an app where you are an admin and in a page where you have admin role.

Related

Facebook graph api - Cannot create offers

I am using the facebook graph api to programmatically create offers on a page, of which the user is an admin of.
I am sure the user is an admin of that page, still I am getting an error to check my admin permission levels (Error below). Any idea why? Any help is appreciated.
If it is of any help, I have added the following scope to my requests: {scope: 'manage_pages,publish_pages'}
{
"error": {
"message": "Invalid parameter",
"type": "OAuthException",
"code": 100,
"error_subcode": 1528104,
"is_transient": false,
"error_user_title": "Check Your Admin Permission Level",
"error_user_msg": "Only some admins of your Page are able to create and edit offers. Talk to the person responsible for your Page about your admin permission level.",
"fbtrace_id": "FgBVmH5BTW0"
}
}
A snapshot of my code is as follows:
accessToken = req.session.access_token;
FB.setAccessToken(accessToken);
FB.api("page-name", {fields: "access_token,id"}, function (res) {
var pageId = res.id;
var pageAccessToken = res.access_token;
FB.setAccessToken(pageAccessToken);
FB.api(pageId + "/offers", 'post', {
title: "Test title",
expiration_time: 'some datetime',
message: "Test offer 1"
}, function (res2) {
resp.send(res2);
});

Facebook custom share alternative to feed dialog

Hi i'm working on a test site to share personalized content non linked to og.
I'm at the point that i have implement the FB.ui method feed but i read that it's deprecated.
So i have looked for the new share_open_graph with object and action.
Now i can create an action and share it, but when i share it don't appear in the board but only in the timeline. and as i read on the rules this function make 2 call that can be passible to ban/suspension.
the site is:
www.paris-web.it/test.html
you can see all the code directy in page/with inspector
function postLike(){
accessToken = FB.getAuthResponse().accessToken;
FB.api(
'me/objects/article',
'post',
{
object: {
"app_id": fbAppId,
"type": "article",
"url": objectToLike,
"title": "my title",
"image": logoImage,
"description": "my desc",
"expiration_time": "2014-07-23"
}
},
function(response) {
console.log(response);
if ( response.error != undefined ){
$("#result").text(response.error.message);
return;
}else{
$("#result").text("succesfull shared "+response.id);
}
FB.ui({
method: 'share_open_graph',
action_type: 'og.shares',
action_properties: JSON.stringify({
object: response.id
})
}, function(r){});
});
}
i'm looking for some solution/alternative and with some example. i'm blocked there from 3 day and i can't find any other solution.
tHANKS
Solved with a dynamic url that generate dynamic og via php.
It's the only solution to have personalizedcontent and don't have problem with google/facebook cache!
You can see the result on the same page linked in OP

Post a public message in Facebook with FB.api

I have tried to post a message on my wall using FB.api(). I posted it successfully but it's showing only for me. I want to make this post public.
In app Configuring permissions i set "Default Activity Privacy" value Public but still message posting private.
I tried to do it by following code:
FB.login(function (response) {
if (response.authResponse) {
var privacy = { 'value': 'EVERYONE' };
var txt = 'my post to test feed post using api';
FB.api('me/feed', 'post', { message: txt, privacy: privacy }, function (response) {
if (!response || response.error) {
alert(JSON.stringify(response.error));
} else {
alert('Post ID: ' + response.id);
}
});
}
}, { scope: 'email,user_likes,publish_actions,publish_stream,read_stream' });
Please check my code.
As said in reference 'privacy' field value should be string.
Try to pass "{ 'value': 'EVERYONE' }" as string, not an object.

how to get user id on facebook request dialog

What i want to do is get the request ID and insert to my database. My request dialog is run well, but the problem is I cannot get 'TO' user id http://developers.facebook.com/docs/reference/dialogs/requests/ , but I still cannot get the request user ID.
here is my coding:
function newInvite(){
//var user_ids = document.getElementsByName("user_ids")[0].value;
FB.ui({
method : 'apprequests',
title: 'X-MATCH',
message: 'Come join US now, having fun here',
},
function getMultipleRequests(requestIds) {
FB.api('', {"ids": requestIds }, function(response) {
console.log(response);
});
}
);
}
any solution on this?
million thanks for help
Have you enable request 2.0 efficient?
If you have enabled, you can get the user id easily as the response like this
{
request: ‘request_id’
to:[array of user_ids]
}
In your callback function, you can use
response.request to get the request ID
response.to to get the array of user ids
And notice that if you use request 2.0, the request ID format will like this
<request_object_id>_<user_id>
If you doesn't enable it, then you can only get the array of request ids and you need to make another api call to get the user id
Edited:
FB.ui({
method : "apprequests",
title : "your title",
message : "your msg"
},
function(response) {
var receiverIDs;
if (response.request) {
var receiverIDs = response.to; // receiverIDs is an array holding all user ids
}
}
);
Then you can use the array "receiverIDs" for further process
For example I sent a request to user id with id "1234", "5678"
The response will like this:
{
request: ‘1234567890’ // example,
to:['1234', '5678']
}
In request 2.0, the full request id will look like this
1234567890_1234
1234567890_5678
Caution: FB doc tell you to manage and delete the request yourself, if you using request 2.0,
remember to delete the id like the above, if you directly delete the request '123456789', all the full request ID with this prefix will be deleted.
==================================================================
If you haven't enable request 2.0, follow the code on the doc page to see how to get the user id by making a api call
function getMultipleRequests(requestIds) {
FB.api('', {"ids": requestIds }, function(response) {
console.log(response);
});
}
The response format for these methods is as follows:
{
"id": "[request_id]",
"application": {
"name": "[Application Name]",
"id": "[Application ID]"
},
"to": {
"name": "[Recipient User Name]",
"id": "[Recipient User ID]"
},
"from": {
"name": "[Sender User ID]",
"id": "[Sender User Name]"
},
"message": "[Request Message]",
"created_time": "2011-09-12T23:08:47+0000"
}
you can implement the callback of api call and getting who is the receiver by response.to.id

Is there a way to post a message to a Facebook group's feed?

I'm working on a Facebook app that uses Facebook groups, and I'd like to open up a Feed dialog to let the user post a notice to the group's feed. I have a user who is in the group and I've got the relevant permissions as well.
I've tried passing the group's Facebook id in the https://developers.facebook.com/docs/reference/dialogs/feed/ feed dialog, but get a Facebook error. There doesn't appear to be a programmatic way to do it either: the group's feed (described at https://developers.facebook.com/docs/reference/api/group/) isn't documented to accept POSTs either. Is there a way to post a message to the group using the Graph API or one of the other API methods?
I just made a test and it's working as any other wall.
I made a POST to 'GROUP_ID/feed' with a message variable with a value and it worked. I logged into the app as the group owner.
Using facebook php-sdk:
$facebook->api('GROUP_ID/feed', 'POST', array(
'message' => 'Testing...'
)));
I would suggest to use javascript instead as it wont cause post back of our website.
Check out my application to see if that what you want -> WooTube
function Promote() {
var lnk =
'http://www.wootube.woolei.com?v=<?php echo $_GET["id"] ?>';
FB.login(function(response) {
if (response.authResponse) {
//Post To WooTube Group
FB.api('/271691796276524/feed', 'post', {
message: lnk,
link: lnk,
},
function(response) {
if (!response || response.error) {
//alert('You have to join the group first!');
} else {
//alert("Successfully Posted to WooTube Group!");
}
});
//Post to Wootube Page
FB.api('/173724382762792/feed', 'post', {
message: lnk,
link: lnk
},
function(response) {
if (!response || response.error) {
//alert('You have to like http://www.facebook.com/WooTubes first!');
} else {
//alert("Successfully Posted to WooTube Page!");
}
});
} else {
alert('Not logged in');
}
}, {
scope: 'publish_stream'
});
}