I am working for a charity which is promoting sign language, and they want to post a video to their FB page every day. There's a large (and growing) number of videos, so they want to schedule the uploads programmatically. I don't really mind what programming language I end up doing this in, but I've tried the following and not got very far:
Perl using
WWW::Facebook::API
(old REST API)my $res = $client->video->upload( title => $name, description => $description, data => scalar(read_file("videos/split/$name.mp4")) );
Authentication is OK, and this correctly posts a
facebook.video.upload
method tohttps://api-video.facebook.com/restserver.php
. Unfortunately, this returns "Method unknown". I presume this is to do with the REST API being deprecated.Facebook::Graph
in Perl orfb_graph
gem in Ruby. (OAuth API)I can't even authenticate. Both of these are geared towards web rather than desktop applications of OAuth, but I think I ought to be able to do:
my $fb = Facebook::Graph->new( app_id => "xxx", secret => "yyy", postback => "https://www.facebook.com/connect/login_success.html" ); print $fb->authorize->extend_permissions(qw(publish_stream read_stream))->uri_as_string;
Go to that URL in my browser, capture the
code
parameter returned, and thenmy $r = $fb->request_access_token($code);
Unfortunately:
Could not fetch access token: Bad Request at /Library/Perl/5.16/Facebook/Graph/AccessToken/Response.pm line 26
Similarly in Ruby, using
fb_graph
,fb_auth = FbGraph::Auth.new(APP_ID, APP_SECRET) client = fb_auth.client client.redirect_uri = "https://www.facebook.com/connect/login_success.html" puts client.authorization_uri( :scope => [:publish_stream, :read_stream] )
Gives me a URL which returns a code, but running
client.authorization_code = <code> FbGraph.debug! access_token = client.access_token!
returns
{ "error": { "message": "Missing client_id parameter.", "type": "OAuthException", "code": 101 } }
Update: When I change the
access_token!
call toaccess_token!("foobar")
to force Rack::OAuth2::Client to put the identifier and secret into the request body, I get the following error instead:{ "error": { "message": "The request is invalid because the app is configured as a desktop app", "type": "OAuthException", "code": 1 } }
How am I supposed to authenticate a desktop/command line app to Facebook using OAuth?