Publish to a friend's wall using Facebook API - php

I know we can publish something on a friend's wall with this:
$publishStream = $facebook->api("/$user/feed", 'post', array(
'message' => "Your Message",
'link' => 'http://example.com',
'picture' => '',
'name' => 'App Name',
'description'=> 'App description'
));
Just by replacing the $user variable with the user id of your friend.
What i wish is simply to choose among my friends, the user profiles i want to write on using check boxes.
this is something already possible if you want to share a fan page for instance. You choose the persons you send the request to.
Thanks in advance for your help

You can use Facebook's Multi-Friend-Selector (MFS).
https://developers.facebook.com/docs/guides/games/custom-muti-friend-selector/
An edited example taken from the Multi-Friend-Selector documentation
function renderMFS() {
// First get the list of friends for this user with the Graph API
FB.api('/me/friends', function(response) {
var container = document.getElementById('mfs');
var mfsForm = document.createElement('form');
mfsForm.id = 'mfsForm';
// Iterate through the array of friends object and create a checkbox for each one.
for(var i = 0; i < Math.min(response.data.length, 10); i++) {
var friendItem = document.createElement('div');
friendItem.id = 'friend_' + response.data[i].id;
friendItem.innerHTML = '<input type="checkbox" name="friends" value="'
+ response.data[i].id
+ '" />' + response.data[i].name;
mfsForm.appendChild(friendItem);
}
container.appendChild(mfsForm);
// Extract selected friends' Facebook ID from value property of checked checkboxes
// Do a for loop to send notification (refer to the link posted below) and publish post to each user's wall
});
}
And is it possible to send notifications before the messages are
written on the walls?
Yes it is possible when you have the Facebook ID. Refer to my answer in How to send Facebook message to friend using Facebook ID?

Related

How to tag user(s) in comment via facebook php sdk?

I'm trying to tag user(s) inside page post comments.
$fb_id = 'facebook_user_id_here';
$fb_name = 'facebook_user_name_and_surname_here';
$request = new FacebookRequest(
$this->session,
'POST',
$comment,
array(
'access_token' => $this->page_access_token, //it is access token of my page
'message => "Text here #[".$fb_id.":1:".$fb_name."]"
)
);
It shows only name and surname without Fb profile URL.
Like CBroe mentions in his comment, at this time this is not possible using the API.
For reference, this is called "mentioning" or "mention tagging", and personal profiles can only do this in messages on open graph actions (docs).
Pages can also mention other pages in comments. (docs)

send message to selected friends in facebook

I have the following code to send messages to selected friends by custom made
$friends = $facebook->api(array(
"method" => "fql.query",
"query" => "SELECT uid,name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())"
));
where $facebook is the one having the details of the application & key values.,
& I get my friends list into the $friends
I'll be having a textarea too to enter the message that has to be sent,
now I'll be passing the selected list of friends & message to a function as follows
function facebook_send_message(to,message) {
FB.ui({
app_id:'MY APP ID',
method: 'send',
name: 'Abcdef',
link: 'http://apps.facebook.com/',
to:to,
message:message
},function(response){alert(response);});
}
when this function was called, a facebook popup opens, but my form in which all these content is placed gets submitted,
I'm not able to send the message to the selected friends, do anyone can help me in this issue..
For sending message with custom text, you have added 'message' parameter to FB.ui, but this feature is Deprecated. You can't pre-fill the message anymore.
This was deprecated might be because of bad advertisements.
So don't use 'message' parameter for message.

Posting to wall users use token

I have php code that posting in the wall of the user that use in my app. But in the post write
"post by _" (My app name).
Code:
$fql_info = $facebook->api($fql_query);
if($fql_info[0][offline_access] == 1)
{
$attachment = array(
'message' => "",
'name' => u("ghfhgfhfgh"),
'description' => u("fghgfhgfh"),
'link' => LINK,
'picture'=> "http://gfhgfhgfhfh"
);
$facebook->api('/'.$f[uid].'/feed', 'POST', $attachment);
$abc.=$f[uid]."\n";
echo $f[uid]."-".$fql_info[0][offline_access]."\n";
}
I want to know how I can to post but without my app name. User as poster itself, not the application has released it.
is it possible?
I guess it's not possible. The app name will appear in the post.
Sorry to say but i don't think this is possible . Facebook would not allow us to do that , it will always say Posted via : [Your APP name]

Cannot post entry to facebook fan page wall as an admin

I am trying in vain to post to a Facebook fan page wall as admin. I want to post new entries with pictures, link, description etc on my fan page wall. This is integrated into my custom cms so that whenever a story is updated on my website, it automatically posts the same on the fan page wall.
The problem is that whenever I post, the post does not appear as posted by admin. It appears as posts by others on the right side of the timeline.
How do I go around the following code so that it posts as admin on my fan page wall? I been looking at it for two days, checked similar stuff on the web and so, but I still cant seem to crack it. Help will be appreciated.
$page_id = 'xxxxxxxxxx';
$article_link = "http://xyz.com/articles/headlines/title-one/";
$result = $facebook->api("/me/accounts");
foreach($result["data"] as $page) {
if($page["id"] == $page_id) {
$page_access_token = $page["access_token"];
break;
}
}
$og_title = "Sample title";
$og_image = "http://xyz.com/images/articles/919161344090182.jpg";
$msg = "some description of the article";
$feed_array = array(
'access_token' => "$page_access_token",
'message' => "$msg",
'picture' => "$og_image",
'link' => "$article_link",
'name' => "$og_title",
'caption' => "$og_title"
);
try {
$page_post = $facebook->api("/$page_id/feed","post",$feed_array);
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
If you want to post as the page - that means that the post will appear as if the page posted an update as it appears here :
Then you will have to use a valid page access token. There is information on how to obtain this kind of token in the Facebook Authentication Documentation. It looks like you already have a token in your code - you can test it using the Facebook Debugger and see if it is still valid.
Another thing you may want to try, instead of appending the token to be one of the parameters of the post array, you could use the setAccessToken() function of the PHP SDK. More details can be found here - https://developers.facebook.com/docs/reference/php/facebook-setAccessToken/
$facebook->setAccessToken($new_access_token);
As a final BTW note, when you specify elements of an array, unless you are wanting to specifically add the quote character, there is no need to wrap the values in quotes.
$feed_array = array(
'access_token' => $page_access_token,
'message' => $msg,
'picture' => $og_image,
...
);
If you want to explicitly add quotes to the values you would have to do something like this -
$feed_array = array(
'string_value' => '"'.$value.'"',
...
);

Delete facebook post with Graph API - trouble getting this to work

I'm using the following to post a message on my Facebook page:
$attachment = array(
'access_token' => $access_token,
'message' => 'This is a test Message 4:',
'name' => "This is a test Name 4",
'link' => "http://slashdot.org/",
'description' => "This is a test Description 4"
);
$ret_code=$facebook->api('/me/feed', 'POST', $attachment);
This works great.
How do I delete the same post using the facebook GRAPH api? I read the docs and it says to issue a POST like:
https://graph.facebook.com/COMMENT_ID?method=delete
To test I set this up in a simple form with submit button, POSTing the data to https://graph.facebook.com/COMMENT_ID?method=delete (substituting COMMENT_ID fro the 11111111111_111111111111 id returned from the original publish call. This returns "This API call requires a valid app_id".
What is the correct way to issue a DELETE command?
Since you are using the php-sdk you just issue this call:
$facebook->api("/COMMENT_ID","DELETE");
You can use the following code:
Http::post('https://graph.facebook.com/'.$fb_action_id, array('method'=>'delete', 'access_token'=>$your_app_access_token));
This post will return a boolean value, true if successed and false if failed.
Its been discussed here Facebook SDK and Graph API Comment Deleting Error
you need to pass the access token too. You can delete all the milestones of a page like follows:
$milestones = $facebook->api('/PAGE_ID/milestones');
foreach($milestones[data] as $milestone)
{
echo $milestone['id'];
$args = array(
'access_token' => $pages_access_token
);
$deleted = $facebook->api($milestone['id'],"delete",$args);
if($deleted)
{
echo " <font color=\"green\">OK</font><br>";
}
else
{
echo " <font color=\"red\">ERR</font><br>";
}
}

Categories