facebookfacebook-graph-apifacebook-pagefacebook-timeline

How to upload custom app image (tab_image) for Timeline Page tabs via API?


Facebook released the new Timeline for Pages today. Apps installed to pages as "tabs" now appear above the timeline with a 111px x 74px size thumbnail "app image". You can customize this on a per-page level (just like the custom tab name) if you navigate the Facebook Page admin interface.

You can update the tab's "custom name" via the Open Graph API, but they do not appear to have updated their API docs to show how to upload a custom tab_image (assuming they will). Is it possible now but undocumented? Has anyone figured out how to do this yet?


Solution

  • Updated 2016:

    With the latest Open Graph 2.5 API tabs endpoint and PHP SDK 5, the code should look like this:

    <?php 
    $fb = new Facebook\Facebook([/* . . . */]);
    $response = $fb->post(
        '/{page-id}/tabs',
        [
            'custom_name'=>'My Custom Tab',
            'custom_image_url'=>'http://publicly.accessible/image.jpg',
            'app_id'=>'{app-id}',
        ],
        '{page-access-token}',
    );
    

    Original 2012 post:

    I figured it out, it's just like uploading an image. The field is called "custom_image". Presumably they will update the documentation soon. It's nice they enabled this API hook so quickly with the new release!

    Here's how to do it with the Facebook PHP SDK:

    <?php
    $page_access_token = 'XXXXXXX'; // you'll need the manage_pages permission to get this
    $facebook = new Facebook(array(
      'appId'  => 'YOUR_APP_ID',
      'secret' => 'YOUR_APP_SECRET',
      'fileUpload' => true, // enables CURL @ file uploads
    ));
    $facebook->api(
      '/PAGE_ID/tabs/TAB_NAME', // looks like "app_xxxx" where xxxx = APP_ID
      'POST' // post to update
      array(
        'custom_image' => '@' . realpath('path/to/my/file.jpg'),
        'custom_name' => 'My App', // give it a custom name if you want too
        'access_token' => $page_access_token // access token for the page
      )
    );
    

    Cheers