Archive for api

Upload and tag a video to facebook via php

Posted in Development, Instructional, Php with tags , , , , , on May 14, 2013 by andkrup

Currently the facebook API documentation doesn’t mention that you can upload a video file to your facebook wall and tag your friends in it. This may be a feature yet to be announced or just hidden.

https://developers.facebook.com/docs/reference/api/video/

The code for connecting to facebook is well-known, here

$facebook = new Facebook(array('appId' => $appId, 'secret' => $appSecret));
$facebook->setAccessToken($accessToken);
$facebook->setFileUploadSupport(true);

Uploading a video to your feed is done like this:

$args = array();
$args['description'] = $videoDescription;
$args['title'] = $videoTitle;
$args['privacy'] = json_encode(array('value' => 'ALL_FRIENDS'));
$args['file'] = "@$videoPath";
$data = $facebook->api('/me/videos', 'post', $args);

Then after the api() function returns the video-id, you can tag the video object, using the undocumented field tags, like so:

$args = array();
$args['tag_uid'] = "$userId";
$data = $facebook->api("/{$videoId}/tags", 'post', $args);

That’s it

Advertisements