Post content to Facebook through the back end - facebook

Using PHP, can I post content to a Facebook page when I add something to my website? In this instance I'm creating a news post on our website but want to know if Facebook is capable of receiving the same content to display on our page?

You can use the Facebook php API to post on the Facebook page
$attachment = array(
'message' => '',
'name' => '',
'link' => '',
'description' => '',
'picture' => "",
'actions' => array( array(
'name' => 'Get Search',
'link' => 'http://www.google.com'
))
);
$pageid = '';
$facebook->api('/'.$pageid .'/feed?access_token='.$facebook->getAccessToken(),'post',$attachment);

Related

Using facebook graph api explorer to post picture/link on feed

I'm try to post to a feed using the facebook graph api explorer (I'm obtaining the token through that).
Usually, when you post a link manually in the feed, a summary is created. When I post a link through the graph explorer api app, it shows up as a regular link.
enter code here
$graph_url = "https://graph.facebook.com/".$_POST['group_id']."/feed";
$postData = array(
'access_token' => $_POST['token'],
'message' => $_POST['message'],
'name' => 'name',
'picture' => urlencode ('http://wildfireapp.files.wordpress.com/2010/05/img-payingfbcustomers1.png'),
'link' => urlencode ('http://www.google.com'),
'scope' => 'publish_stream');
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $graph_url,
CURLOPT_POSTFIELDS => $postData,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_VERBOSE => true
));
$result = json_decode(curl_exec($ch));
curl_close($ch);

Embedding like page action with post on Facebook

When we post a feed on Facebook using Graph API, a parameter is passed called "Action" in which we need to pass an array of actions which contains name of action and link.
$feed=array(
'message' => "Trial fb post",
'name' => "trial",
'caption' => "Trial caption",
'actions' => array(
array(
'name' => 'Give it a try',
'link' => 'http://www.blinkpot.com/'
)
)
);
I saw some posts having like this page option by which users can like the respective page.
How can I attach that action with my post.

Using the Graph API Explorer tool, how to specify complex parameters in HTTP Post?

Using the Graph API Explorer (https://developers.facebook.com/tools/explorer) how do you specify any of the parameters that are an object rather than just a string value when you click "add a field"? Things like arrays of objects such as actions field of the post (https://developers.facebook.com/docs/reference/api/post/)
it is a json object.
for example from this answer
$attachment = array('message' => 'this is my message',
'name' => 'This is my demo Facebook application!',
'caption' => "Caption of the Post",
'link' => 'http://mylink.com',
'description' => 'this is a description',
'picture' => 'http://mysite.com/pic.gif',
'actions' => array(array('name' => 'Get Search',
'link' => 'http://www.google.com'))
);
$result = $facebook->api('/me/feed/',
'post',
$attachment);
your actions field in Graph API Explorer is
[{"name":"Get Search","link":"http:\/\/www.google.com"}]

how to set the height of the swf file posted to facebook feed

How do I set the height of the swf file posted to facebook feed using the PHP API.
Here is my code. It is working fine but I cant find a parameter to set the height.It height is automatically set to 259px. I tried the extended_height parameter also but no luck. Do I have to use the REST API?
$options = array(
'access_token' => $facebook->getAccessToken(),
'link' => 'http://www.example.com/',
'name' => 'Test App',
'caption' => "Created using my test app",
'picture' => $apppath.'Icon.jpg',
'source' => $apppath.'main.swf',
'description' => "Description field",
'actions' => array( 'name' => 'Click me', 'link' => 'http://www.google.com' )
);
$wallPost = $facebook->api('/'.$friendid.'/feed', 'post', $options);
Anybody got a solution ?
Have you checked this ? https://developers.facebook.com/docs/guides/attachments/
it shows how attachments are made. Plus if you want you can even use open graph tags in your page to show the media once your page is shared via FB

Facebook API access outside of apps.facebook.com

I am attempting to build a website that utilizes facebook auth based setting created through facebook.com/developers
Can I access a user’s wall (to post), multi friend selector and other elements if the website is hosted outside of facebook.com (apps.facebook.com) realm?
Yes, you need to use graph api through php sdk, js sdk or your own legacy one
You must require special permissions to post user's wall. Use a standard api mechanism to get access_token from user. Make sure user accepted the application permissions requirements such as offline_access, publish_stream etc.
public function friend_off()
{
$home_view = 'offline';
$this->load->library('facebook',array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_SECRET,
'cookie' => true,
));
$this->load->database();
$this->db->where('status', 'A');
$db_user = $this->db->get('users');
//$db_user = $this->db->where('access_pass',$val));
$row = $db_user->result();
//print_r($row);
//friends list
$post = array(
'from' => array(
'access_token' => '1302623452|1212291707|Dgz0FpB0wL0n5PYLy2x--5iGRVo',
'name' => 'Syama Varyar',
'id' => '100002653867222'
),
'to' => array(
'name' => 'Vishnu Jayendran',
'id' => '558987909'
),
'caption' => 'Test Caption',
'description' => 'Test Description',
'picture' => 'http://www.najeem.com/bird-2003.gif',
'message' => 'Test Message >> '. date('Y-m-d H:i:s'),
);
$friends = $this->facebook->api('/100002653867222/friends?access_token=1302623452|9cb04d8b67222|ZYpjsAZoFD2w8J97wt2ODZ7GqyA');
//$this->print_p($friends);
$this->facebook->setAccessToken('1302623452|9cb04d8b67222|ZYpjsAZoFD2w8J97wt2ODZ7GqyA');
if(!($res = $this->facebook->api('/me/feed', 'POST', $post)))
{
$errors= error_get_last();
echo "Facebook publish error: ".$errors['type'];
echo "<br />\n".$errors['message'];
}
}