Thread Facebook API – Post im eingenen Namen
(6 answers)
Opened by mika at 2015-06-20 16:00
Hallo,
ich habe mir ein Skript geschrieben, womit ich Bilder und Text-Messages auf meine Facebook-Pinnwand veröffentliche: Code (perl): (dl
)
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"); } Ganz qick'n'dirty – Das Skript tut. Die Beiträge, werden allerdings nur mir angezeigt und nicht meinen Freunden auf Facebook. Kennt sich damit jemand aus und kann mir weiterhelfen? Sicher ist das ein Rechte/Privatsphäre Problem? Danke; Mika Edit: Hier noch die Benutzung: perl ./path/to/fbupload.pl --message "hello to my frinds on fb" # post a text-message perl ./path/to/fbupload.pl --link "http://example.net/" --message "a link 4 u" # post a weblink with a describing text-message perl ./path/to/fbupload.pl --url http://example.net/image.jpg # post a file from the internet to fb perl ./path/to/fbupload.pl --content-file ./image.jpg # post a file from your hard-drive to fb Die Kommandozeilen Argumente können fast beliebig kombiniert werden... Last edited: 2016-12-12 10:57:53 +0100 (CET) |