Simple example to post to a Facebook fan page via PHP? -


i've done lot of searching , i've found outdated tutorials don't work...

i have site made php , when submit particular form in admin area, want publish facebook "fan page"

there no rss available, have example directly post facebook fan page (not user wall) using php sdk?

thank you!

finally, after lot of tests, worked, without php sdk. step step guide:

1. permissions , page token

go https://developers.facebook.com/tools/explorer/ , select app first drop down menu, in left.

click on button "get access token", , in "select permissions" window, click in "extended permissions" , check manage_pages , publish_stream, , click in "get access token" blue button.

you may asked in step grant permissions app access facebook account, accept.

next, click @ end of text field next "get" drop down, , replace numbers for: me/accounts, , click in blue button next text field.

you'll tokens pages, including app page. find page name in list, this: "name": "your page name"

when located page, copy access token page (will long), can this: "access_token": "xxxxxxxx". copy id of page: "id": "xxxxx".

that's step, can start coding now.

2. post page wall via php

first, script, you'll need server supporting curl.

we start php document defining page access token , page id we've in 1st step:

<?php $page_access_token = 'xxxxxxx'; $page_id = 'yyyyyyyy'; 

after that, create array info post our page wall:

$data['picture'] = "http://www.example.com/image.jpg"; $data['link'] = "http://www.example.com/"; $data['message'] = "your message"; $data['caption'] = "caption"; $data['description'] = "description"; 

you can of course, use other post parameter described in https://developers.facebook.com/docs/reference/api/post/ , if don't need 1 or many of parameters above can delete it.

ok, @ point add array access token:

$data['access_token'] = $page_access_token; 

and set our post url, post in our page:

$post_url = 'https://graph.facebook.com/'.$page_id.'/feed'; 

and last step, we'll use curl post our message in our page wall:

$ch = curl_init(); curl_setopt($ch, curlopt_url, $post_url); curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, $data); curl_setopt($ch, curlopt_returntransfer, 1); $return = curl_exec($ch); curl_close($ch); ?> 

after that, can save our php document, , try execute it. post may appear in our facebook page.

hope code helps other people same problem!


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -