#!/usr/bin/env perl # fb.pl # See also: https://developers.facebook.com/tools/explorer # https://developers.facebook.com/docs/graph-api/reference/user/feed # https://developers.facebook.com/docs/graph-api/reference/photo use diagnostics; use strict; use utf8; use warnings; use Getopt::Long; use JSON; use LWP::UserAgent; my $ua = LWP::UserAgent->new; #$ua->timeout(10); #$ua->agent(""); # don't identify #$ua->from('user\@example.org'); #$ua->show_progress(1); # boolean my $fb_access_token = "***"; my $fb_app_id = "***"; my $fb_app_secret = "***"; my $node_id = "me"; my $edge_name = "feed"; my $content_file = undef; my $verbose = undef; my $quiet = undef; my %form; $form{"access_token"} = $fb_access_token; GetOptions( "verbose" => \$verbose, "quiet" => \$quiet, "content-file=s" => \$content_file, "node-id=s" => \$node_id, "edge-name=s" => \$edge_name, "access-token=s" => \$form{"access_token"}, "actions=s" => \$form{"actions"}, "caption=s" => \$form{"caption"}, "link=s" => \$form{"link"}, "message=s" => \$form{"message"}, "object-attachment=s" => \$form{"object_attachment"}, "place=s" => \$form{"place"}, "privacy=s" => \$form{"privacy"}, "tags=s" => \$form{"tags"}, "url=s" => \$form{"url"}, ) or die("Error in command line argumentsn"); # Remove undefined values for ( keys(%form) ) { delete( $form{$_} ) unless ( defined( $form{$_} ) ); } # Pass request to the user agent and get a response back my $res; if ( defined $content_file ) { my $query = "method=POST"; for ( keys %form ) { $query .= sprintf "&%s=%s", $_, $form{$_}; } %form = ( "fn" => [ ( $content_file eq "-" ) ? "/dev/stdin" : $content_file ], ); $res = $ua->post( sprintf( "https://graph.facebook.com/%s/%s?%s", $node_id, $edge_name, $query ), Content_Type => "form-data", Content => \%form ); } else { $res = $ua->post( sprintf( "https://graph.facebook.com/%s/%s", $node_id, $edge_name ), Content_Type => "form-data", Content => \%form ); } # Check the outcome of the response if ( $res->is_success ) { if ( !$quiet ) { printf( STDERR "%s\n", $res->status_line ) if ($verbose); printf( STDOUT "%s\n", $res->content ); } #my $hash = decode_json( $res->content ); } else { printf( STDERR "%s\n", $res->status_line ); die("$0: FAILED\n"); }