Leser: 19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
#!/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"); }