Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Can now post posts and events directly to other pages you control wit…

…hout switching access tokens.
  • Loading branch information...
commit be3640b1294494a280544d2a8902385d6017081b 1 parent 9e72a90
@rizen authored
View
2  Changes
@@ -1,6 +1,8 @@
1.0000 2010-12-09
- Updated recipe2 example to use more modern Dancer features.
- Merged POD patch from fayland.
+ - Can now post posts and events directly to other pages you control without
+ switching access tokens.
- Added set_source(), set_privacy(), set_actions(), add_actions(),
set_target_countries(), set_target_cities(), set_target_regions(), and
set_target_locales to Facebook::Graph::Publish::Post.
View
25 author.t/publish_event.t
@@ -1,4 +1,4 @@
-use Test::More tests => 4;
+use Test::More tests => 8;
use lib '../lib';
use_ok('Facebook::Graph');
@@ -20,3 +20,26 @@ my $out = $response->as_hashref;
ok(ref $out eq 'HASH', 'got a hash back') or debug($response->as_json);
ok(exists $out->{id}, 'we got back an id');
+$response = $fb->add_event(176943642329328)
+ ->set_start_time(DateTime->new(year => 2012, month => 1, day => 1))
+ ->set_end_time(DateTime->new(year => 2012, month => 1, day => 2))
+ ->set_name('The Apocalypse')
+ ->set_description('The date that idiots believe the end of the world is coming.')
+ ->set_location('The Whole World!')
+ ->publish;
+$out = $response->as_hashref;
+ok(ref $out eq 'HASH', 'got a hash back from community page') or debug($response->as_json);
+ok(exists $out->{id}, 'we got back an id from community page');
+
+
+$response = $fb->add_event(182872885058638)
+ ->set_start_time(DateTime->new(year => 2012, month => 1, day => 1))
+ ->set_end_time(DateTime->new(year => 2012, month => 1, day => 2))
+ ->set_name('The Apocalypse')
+ ->set_description('The date that idiots believe the end of the world is coming.')
+ ->set_location('The Whole World!')
+ ->publish;
+$out = $response->as_hashref;
+ok(ref $out eq 'HASH', 'got a hash back from official page') or debug($response->as_json);
+ok(exists $out->{id}, 'we got back an id from official page');
+
View
16 author.t/publish_to_feed.t
@@ -1,4 +1,4 @@
-use Test::More tests => 8;
+use Test::More tests => 10;
use lib '../lib';
use_ok('Facebook::Graph');
@@ -16,7 +16,6 @@ my $out = $response->as_hashref;
ok(ref $out eq 'HASH', 'got a hash back on simple post') or debug($response->as_json);
ok(exists $out->{id}, 'we got back an id on simple post');
-
$response = $fb->add_post
->set_message('TESTING: I like Perl.')
->set_picture_uri('http://www.perl.org/i/camel_head.png')
@@ -30,8 +29,19 @@ ok(exists $out->{id}, 'we got back an id on complex post');
$response = $fb->add_post(176943642329328)
- ->set_message('Testing')
+ ->set_message('This is me testing')
+ ->set_link_uri('http://www.perl.org/')
->publish;
$out = $response->as_hashref;
ok(ref $out eq 'HASH', 'got a hash back on simple post to community page') or debug($response->as_json);
ok(exists $out->{id}, 'we got back an id on simple post to community page');
+
+
+$response = $fb->add_post(182872885058638)
+ ->set_message('This is me testing')
+ ->set_link_uri('http://www.perl.org/')
+ ->publish;
+$out = $response->as_hashref;
+ok(ref $out eq 'HASH', 'got a hash back on simple post to community page') or debug($response->as_json);
+ok(exists $out->{id}, 'we got back an id on simple post to community page');
+
View
20 lib/Facebook/Graph.pm
@@ -113,7 +113,7 @@ sub picture {
sub add_post {
my ($self, $object_name) = @_;
my %params;
- if ($self->has_access_token) {
+ if ($object_name) {
$params{object_name} = $object_name;
}
if ($self->has_access_token) {
@@ -178,8 +178,11 @@ sub add_link {
}
sub add_event {
- my ($self) = @_;
+ my ($self, $object_name) = @_;
my %params;
+ if ($object_name) {
+ $params{object_name} = $object_name;
+ }
if ($self->has_access_token) {
$params{access_token} = $self->access_token;
}
@@ -374,10 +377,14 @@ An profile id like C<sarahbownds> or an object id like C<16665510298> for the Pe
-=head2 add_post ( )
+=head2 add_post ( [ id ] )
Creates a L<Facebook::Graph::Publish::Post> object, which can be used to publish data to a user's feed/wall.
+=head3 id
+
+Optionally provide an object id to place it on. Requires that you have administrative access to that page/object.
+
=head2 add_like ( id )
@@ -407,10 +414,15 @@ Creates a L<Facebook::Graph::Publish::Note> object, which can be used to publish
Creates a L<Facebook::Graph::Publish::Link> object, which can be used to publish links.
-=head2 add_event ( )
+=head2 add_event ( [id] )
Creates a L<Facebook::Graph::Publish::Event> object, which can be used to publish events.
+=head3 id
+
+Optionally provide an object id to place it on. Requires that you have administrative access to that page/object.
+
+
=head2 rsvp_maybe ( id )
View
3  lib/Facebook/Graph/Publish/Event.pm
@@ -69,6 +69,9 @@ sub set_end_time {
around get_post_params => sub {
my ($orig, $self) = @_;
my $post = $orig->($self);
+ unless ($self->object_name eq 'me') {
+ push @$post, page_id => $self->object_name;
+ }
if ($self->has_name) {
push @$post, name => $self->name;
}
Please sign in to comment.
Something went wrong with that request. Please try again.