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.'"',
...
);
Related
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)
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]
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>";
}
}
Greetings
Here's what's up:
I'm working on an app where the user or a page they administrate is tagged in their own image, however, tagging a page they administrate doesn't function, I have no trouble with the user being tagged.
Here's some code:
$tdata = array('tag_uid' => $fb_id,'x' => 0,'y' => 0);
$datatags[] = $tdata;
$attachment = array(
'access_token' => $access_token,
'tags' => $datatags
);
$attachment['image'] = '#'.realpath($image_name.);
$result = $facebook->api('/'.$album_id.'/photos', 'POST', $attachment);
$fb_id is either the ID for the user or the page. which is grabbed using /me/accounts in the Graph API
Thanks!
Per the documentation you cannot do this:
You can specify which user to tag using two methods: in the URL path
as PHOTO_ID/tags/USER_ID, or in a URL parameter as
PHOTO_ID/tags?to=USER_ID. Currently, you cannot tag a Page in a photo
using this API.
https://developers.facebook.com/docs/reference/api/photo/
Hi I am using the graph API to post to the the wall of a friend.
However I do not want the post to be visible on any News Feeds
(the posting user, the friend being posted to, or anyone else).
How can I achieve this. Here is my wall post code:
function fb_post($to_uid,$acToken) {
$result = false;
global $fb;
$feed_dir = '/'.$to_uid.'/feed/';
$message_str = 'This is a message';
$msg_body = array('access_token' => $acToken,
'message' => $message_str,
'name' => 'Wall Post',
'caption' => "I posted to your wall",
'link' => 'http://www.wallpost.com',
'description' => 'Learn how to post to peoples walls',
'picture' => 'http://image.com/myimage.jpg',
'actions' => array(array('name' => 'Wall Post',
'link' => 'http://www.wallpost.com'))
);
try {
$result = $fb->api($feed_dir, 'post', $msg_body);
}
catch (Exception $e) {
echo "Not sent";
}
}
Thanks.
Short answer is no.
Facebook's recent lists and so on are a dynamic amalgamation of posts - a post can't be marked to opt-out of this, Facebook decides its relevancy and coverage.
A user may have their profile configured to so that postings of certain types/from certain applications are handled in a specific way, but there's nothing you can personally do about that - and I still don't think it encompasses options to hide posts from feeds, mainly just disallow them from their wall in the first place.
You can add 'privacy' => '{value: SELF}'. However, it work for users who are already in application. So friend of user who posting something to his friend's wall should be authorized in our application as well