Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Upload a Photo to a Facebook Page's Timeline as the Facebook Page itself, Not to the user feed
    text
    copied! <p>OK so the cod below basically works fine, WHEN this line is like this:</p> <pre class="lang-php prettyprint-override"><code>$post_url = '/'.$userPageId.'/feed'; </code></pre> <p>This successfully posts to the Facebook Page Timeline. But I want to upload a photo, and when I change this line to</p> <pre class="lang-php prettyprint-override"><code>$post_url = '/'.$userPageId.'/photos'; </code></pre> <p>It posts the photo... but it posts to the User Feed, instead of AS the Facebook Page.</p> <p>I want this to post the photo to the Facebook Page Timeline</p> <p>[config.php]</p> <pre class="lang-php prettyprint-override"><code>&lt;?php include_once("inc/facebook.php"); ################################## //Call Facebook API // Required facebook permissions $fbPermissions = 'publish_stream,manage_pages,photo_upload'; $facebook = new Facebook(array( 'appId' =&gt; $appId, 'secret' =&gt; $appSecret, 'fileUpload' =&gt; true, 'cookie' =&gt; true )); $fbuser = $facebook-&gt;getUser(); ?&gt; </code></pre> <p>[process.php]</p> <pre class="lang-php prettyprint-override"><code>&lt;?php include_once("config.php"); if($_POST) { //Post variables we received from user $userPageId = $_POST["userpages"]; $userMessage = $_POST["message"]; if(strlen($userMessage)&lt;1) { //message is empty $userMessage = 'No message was entered!'; } //HTTP POST request to PAGE_ID/feed with the publish_stream $post_url = '/'.$userPageId.'/photos'; //posts message on page statues $msg_body = array( 'source' =&gt; '@' . 'test.jpg', 'message' =&gt; "yo yo yo", ); if ($fbuser) { try { $postResult = $facebook-&gt;api($post_url, 'post', $msg_body ); } catch (FacebookApiException $e) { echo $e-&gt;getMessage(); } } else { $loginUrl = $facebook-&gt;getLoginUrl( array('redirect_uri'=&gt;$homeurl,'scope'=&gt;$fbPermissions) ); header('Location: ' . $loginUrl); } //Show sucess message if($postResult) { } } ?&gt; </code></pre> <p>[index.php] (for logging in)</p> <pre class="lang-php prettyprint-override"><code>&lt;?php include_once("config.php"); if ($fbuser) { try { $user_profile = $facebook-&gt;api('/me'); //Get user pages details using Facebook Query Language (FQL) $fql_query = 'SELECT page_id, name, page_url FROM page ' .'WHERE page_id IN (SELECT page_id FROM page_admin WHERE uid=' .$fbuser.')'; $postResults = $facebook-&gt;api( array( 'method' =&gt; 'fql.query', 'query' =&gt; $fql_query ) ); } catch (FacebookApiException $e) { echo $e-&gt;getMessage(); $fbuser = null; } } else { //Show login button for guest users $loginUrl = $facebook-&gt;getLoginUrl( array('redirect_uri'=&gt;$homeurl,'scope'=&gt;$fbPermissions) ); echo '&lt;a href="'.$loginUrl. '"&gt;&lt;img src="images/facebook-login.png" border="0"&gt;&lt;/a&gt;'; $fbuser = null; } if($fbuser &amp;&amp; empty($postResults)) { /* if user is logged in but FQL is not returning any pages, we need to make sure user does have a page OR "manage_pages" permissions isn't granted yet by the user. Let's give user an option to grant permission again. */ $loginUrl = $facebook-&gt;getLoginUrl( array('redirect_uri'=&gt;$homeurl,'scope'=&gt;$fbPermissions) ); echo '&lt;br /&gt;Could not get your page details!'; echo '&lt;br /&gt;&lt;a href="'.$loginUrl.'"&gt;Click here to try again!&lt;/a&gt;'; } elseif ($fbuser &amp;&amp; !empty($postResults)) { //Everything looks good, show message form. } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload