0

I am trying to upload video to facebook page as page admin with the call to action:

// Post Data
$action_call_array = array('type' => 'LEARN_MORE', 'value' => array('link' => 'http://www.google.com'));
$data = [
  'title'        => 'Demo Title',
  'description'  => 'Demo Description

  http://www.google.com
  http://hk.yahoo.com',
  'source'       => new CURLFile('video/video_1mb.mp4', 'video/mp4'),
  'call_to_action' => $action_call_array,
  'access_token' => FACEBOOK_PAGE_TOKEN, // MUST BE INCLUDED !!!
];

// Post Url
$post_url = 'https://graph-video.facebook.com/'.FACEBOOK_PAGE_ID.'/videos';

// CURL
$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);

// result
$j = json_decode($return);
$page_post_id = $j->id;
var_dump($return);

Without the call to action, it works. But after adding the call to action, it returns me the following error:

string(196) "{"error":{"type":"Exception","message":"No Call To Action Type was parseable. Please refer to the call to action api documentation","code":1373054,"is_transient":false,"fbtrace_id":"H9GksxYBdQx"}}"

Looks like the way I add the call to action is not correct. But I don't really know how to fix it.

Alex Poon
  • 101
  • 4
  • 14

1 Answers1

0

I put the call to action into url parameter and it is working now!

            // Post Data
            $fb_action = 'LEARN_MORE';
            $fb_action_link = 'http://www.google.com';
            $action_call_array = array('type' => $fb_action, 'value' => array('link' => $fb_action_link));
            $params = http_build_query(array('call_to_action' => $action_call_array));
            $data = [
              'title'        => 'Demo Title',
              'description'  => 'Demo Description

              http://www.google.com
              http://hk.yahoo.com',
              'source'       => new CURLFile('video/video_1mb.mp4', 'video/mp4'),
              'access_token' => FACEBOOK_PAGE_TOKEN, // MUST BE INCLUDED !!!
            ];

            // Post Url
            $post_url = 'https://graph-video.facebook.com/'.FACEBOOK_PAGE_ID.'/videos?'.urldecode($params);

            // CURL
            $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);

            // result
            $j = json_decode($return);
            $page_post_id = $j->id;
Alex Poon
  • 101
  • 4
  • 14