Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jhthorsen/mojo-facebook
Talk to facebook
https://github.com/jhthorsen/mojo-facebook
Last synced: 27 days ago
JSON representation
Talk to facebook
- Host: GitHub
- URL: https://github.com/jhthorsen/mojo-facebook
- Owner: jhthorsen
- Created: 2012-09-02T20:56:10.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2013-10-01T10:35:12.000Z (over 11 years ago)
- Last Synced: 2024-12-04T20:51:54.631Z (27 days ago)
- Language: Perl
- Size: 181 KB
- Stars: 0
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README
- Changelog: Changes
Awesome Lists containing this project
README
NAME
Mojo::Facebook - Talk with FacebookVERSION
0.0402DESCRIPTION
This module implements basic actions to the Facebook graph protocol.SYNOPSIS
use Mojo::Facebook;
my $fb = Mojo::Facebook->new(access_token => $some_secret);# fetch facebook name
Mojo::IOLoop->delay(
sub {
my($delay) = @_;
$fb->fetch({
from => '1234567890',
fields => 'name',
}, $delay->begin);
},
sub {
my($delay, $res) = @_;
warn $res->{error} || $res->{name};
},
)# fetch cover photo url
$fb->fetch({
from => '1234567890',
fields => ['cover']
}, sub {
my($fb, $res) = @_;
return $res->{errors} if $res->{error};
warn $res->{cover}{source}; # URL
});ERROR HANDLING
Facebook JSON errors will be set in the $res hash returned to the
callback:Error messages
* Could not decode JSON from Facebook* $fb_json->{error}{message}
* HTTP status message
* Unknown error from JSON structure
ATTRIBUTES
access_token
This attribute need to be set when doing "fetch" on private objects or
when issuing "post". This is not "code" query param from the Facebook
authentication process, something which need to be fetched from Facebook
later on. See the source code forMojolicious::Plugin::OAuth2 for
details.$oauth2->get_token(facebook => sub {
my($oauth2, $access_token) = @_;
$fb = Mojo::Facebook->new(access_token => $access_token);
$fb->post({
to => $fb_uid,
message => "Mojo::Facebook works!",
}, sub {
# ...
});
});app_namespace
This attribute is used by "publish" as prefix to the publish URL:https://graph.facebook.com/$id/$app_namespace:$action
scheme
Used to either run requests over "http" or "https". Default to "https".METHODS
fetch
$self->fetch({
from => $id,
fields => [...]
ids => [...],
limit => $Int,
offset => $Int,
}, $callback);Will fetch information from Facebook about a user.
$id can be ommitted and will then default to "me". $callback will be
called like this:$callback->($self, $res);
$res will be a hash-ref containing the result. Look for the "error" key
to check for errors.comment
$self->comment({ on => $id, message => $str }, $callback);Will add a comment to a graph element with the given $id.
$callback will be called like this:
$callback->($self, $res);
$res will be a hash-ref containing the result. Look for the "error" key
to check for errors.publish
$self->publish({
to => $id,
action => $str,
$object_name => $object_url,# optional
start_time => $DateTime,
end_time => $DateTime,
expires_in => $int,
message => $str,
place => $facebook_id,
ref => String,
tags => "$facebook_id,...",# any other key/value is considered to be custom
$custom_attribute => $any,
});Publish a story at $who's wall, looking like this:
.--------------------------------------.
| $who $action a $object_name ... $app |
| |
| .----------. |
| | $image | [$url]($title) |
| | | $descripton ... |
| '----------' |
'--------------------------------------'Required HTML:
$callback will be called like this:
$callback->($self, $res);
$res will be a hash-ref containing the result. Look for the "error" key
to check for errors.delete_object
$self->delete_object($id, $callback);Will try to remove an object from Facebook.
&callback will be called like this:
$callback->($self, $res);
$res will be a hash-ref containing the result. Look for the "error" key
to check for errors.picture
$url = $self->picture;
$url = $self->picture($who, $type);Returns a Mojo::URL object with the URL to a Facebook image.
$who defaults to "me". $type can be "square", "small" or "large".
Default to "square".COPYRIGHT & LICENSE
This library is free software. You can redistribute it and/or modify it
under the same terms as Perl itself.AUTHOR
Jan Henning Thorsen - [email protected]