title: Uploading photos to a Facebook Page as the Page itself, programmatically in PHP
body: <h1>Background</h1>
  
  <p>I'm having a bit of trouble finding out just how to programmatically post photos to a <a href="https://www.facebook.com/FacebookPages" rel="nofollow"><strong>Facebook Page</strong></a>. I've read through the <a href="https://developers.facebook.com/docs/authentication/pages/" rel="nofollow">Facebook Documentation on Authenticating as a Page</a>, but <a href="https://developers.facebook.com/docs/authentication/server-side/" rel="nofollow">all the examples involve Facebook Users</a>. So far I've just generated the needed access tokens manually using Facebook's <a href="https://developers.facebook.com/tools/explorer/" rel="nofollow">Graph API Explorer</a>. <sub>(3)</sub></p>
  
  <h1>What I've tried</h1>
  
  <p>Using this simple code, I was successful in uploading the picture, however it was posted on my <strong>own</strong> wall, in my <strong>own</strong> album under my <strong>own</strong> name, not the on the <strong>Facebook Page</strong>, in the <strong>Facebook Page</strong>'s album under the <strong>Facebook Page</strong>'s name. I need to post it on a specific <strong>Facebook Page</strong> as the <strong>Facebook Page</strong> itself. <sub>(1)</sub></p>
  
  <pre><code>&lt;?php
  require 'facebook-php-sdk/src/facebook.php';
  require 'config.php';
  
  $facebook = new Facebook(array(
      'appId' =&gt; $config['facebook_appId'],
      'secret' =&gt; $config['facebook_appSecret'],
      'fileUpload' =&gt; true
  ));
  
  $facebook-&gt;setAccessToken($config['facebook_pageAccessToken']);
  
  $args = array(
      'message' =&gt; 'Facebook API test',
      'source' =&gt; '@'.realpath(__DIR__.'/404.jpg')
  );
  
  $data = $facebook-&gt;api('/'.$config['facebook_pageId'].'/photos', 'post', $args);
  </code></pre>
  
  <h1>About the code</h1>
  
  <ul>
  <li><code>$config['facebook_appId']</code> is from a dummy test app I created</li>
  <li><code>$config['facebook_appSecret']</code> is from a dummy test app I created</li>
  <li><code>$config['facebook_pageAccessToken']</code> is generated from the <a href="https://developers.facebook.com/tools/explorer" rel="nofollow">Graph API Explorer</a> using the scope <code>manage_pages</code>, <code>publish_stream</code>, <code>photo_upload</code> and <code>offline_access</code> <sub>(3)</sub>
  <ul>
  <li><strong>As a side note to potential future visitors, it turns out I generated a User Access Token instead of a Page Access Token, which is the reason it was posted on my own wall, in my own album as myself.</strong></li>
  </ul></li>
  <li><code>$config['facebook_pageId']</code> is the ID of the page (which I also found using the <a href="https://developers.facebook.com/tools/explorer" rel="nofollow">Graph API Explorer</a>)</li>
  <li>Upon successful completion <code>$data</code> contains the ID of the image and the wall post(?) it seems</li>
  </ul>
  
  <h1>Question summary</h1>
  
  <ol>
  <li><strong>How can I post photos to a Facebook Page as the Facebook Page itself?</strong></li>
  <li>This is for a project where developers are coming and going. Is there a way for me to have an <strong>immutable</strong> Page Access Token independent of a specific Facebook User <strong>OR</strong> dependent on a (dummy) Facebook App <strong>OR</strong> generating one on the fly somehow?</li>
  <li><strong>How can I (if necessary) authenticate as a Facebook Page - giving me a Page Access Token, programmatically in PHP?</strong></li>
  </ol>
  
  <p>Code examples or links to <strong>concise</strong> documentation and/or tutorials preferably with examples will be much appreciated.</p>