| 1 | package Facebook::Graph::AccessToken; | ||||||||||||||||||||||||||||
| 2 | 4 | $Facebook::Graph::AccessToken::VERSION = '1.1205'; | |||||||||||||||||||||||||||
| 3 | 4 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use Facebook::Graph::AccessToken::Response; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Facebook::Graph::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 4 | with 'Facebook::Graph::Role::Uri'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 4 | has app_id => ( | |||||||||||||||||||||||||||
| 9 | is => 'ro', | ||||||||||||||||||||||||||||
| 10 | required=> 1, | ||||||||||||||||||||||||||||
| 11 | ); | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 4 | has secret => ( | |||||||||||||||||||||||||||
| 14 | is => 'ro', | ||||||||||||||||||||||||||||
| 15 | required=> 1, | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 4 | has postback => ( | |||||||||||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||||||||||
| 20 | required=> 1, | ||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 4 | has code => ( | |||||||||||||||||||||||||||
| 24 | is => 'ro', | ||||||||||||||||||||||||||||
| 25 | required=> 0, | ||||||||||||||||||||||||||||
| 26 | predicate=> 'has_code', | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 4 | has access_token => ( | |||||||||||||||||||||||||||
| 30 | is => 'ro', | ||||||||||||||||||||||||||||
| 31 | required => 0, | ||||||||||||||||||||||||||||
| 32 | predicate => 'has_access_token', | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 2 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=3 SCAR=13.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 37 | 2 | ▶ | die "Either code or access_token is required" if not $self->has_code and not $self->has_access_token; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->has_code || $self->has_access_token
MC/DC0%0/2
$self->has_code || $self->has_access_token
$self->has_code
$self->has_access_token
Truth table33%1/3
A || B
A= $self->has_codeB= $self->has_access_token
| |||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub uri_as_string { | ||||||||||||||||||||||||||
|
Subroutine
uri_as_string: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 42 | 0 | my $uri = $self->uri; | |||||||||||||||||||||||||||
| 43 | 0 | $uri->path('oauth/access_token'); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if($self->has_code) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | $uri->query_form( | |||||||||||||||||||||||||||
| 47 | client_id => $self->app_id, | ||||||||||||||||||||||||||||
| 48 | client_secret => $self->secret, | ||||||||||||||||||||||||||||
| 49 | redirect_uri => $self->postback, | ||||||||||||||||||||||||||||
| 50 | code => $self->code, | ||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | else { | ||||||||||||||||||||||||||||
| 54 | 0 | $uri->query_form( | |||||||||||||||||||||||||||
| 55 | grant_type => 'fb_exchange_token', | ||||||||||||||||||||||||||||
| 56 | client_id => $self->app_id, | ||||||||||||||||||||||||||||
| 57 | client_secret => $self->secret, | ||||||||||||||||||||||||||||
| 58 | redirect_uri => $self->postback, | ||||||||||||||||||||||||||||
| 59 | fb_exchange_token => $self->access_token, | ||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | return $uri->as_string; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | sub request { | ||||||||||||||||||||||||||
|
Subroutine
request: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 68 | 0 | return Facebook::Graph::AccessToken::Response->new( | |||||||||||||||||||||||||||
| 69 | response => Facebook::Graph::Request->new->get($self->uri_as_string)->response | ||||||||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 4 | 1; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =head1 NAME | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | Facebook::Graph::AccessToken - Acquire an access token from Facebook. | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =head1 VERSION | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | version 1.1205 | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | my $fb = Facebook::Graph->new( | ||||||||||||||||||||||||||||
| 87 | secret => $facebook_application_secret, | ||||||||||||||||||||||||||||
| 88 | app_id => $facebook_application_id, | ||||||||||||||||||||||||||||
| 89 | postback => 'https://www.yourapplication.com/facebook/postback', | ||||||||||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||||||||||
| 91 | my $token_response_object = $fb->request_access_token($code_from_authorize_postback); | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | my $token_string = $token_response_object->token; | ||||||||||||||||||||||||||||
| 94 | my $token_expires_epoch = $token_response_object->expires; | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | Allows you to request an access token from Facebook so you can make privileged requests on the Graph API. | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =head1 METHODS | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =head2 new ( [ params ] ) | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =over | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =item params | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | A hash or hashref of parameters to pass to the constructor. | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =over | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =item app_id | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | The application id that you get from Facebook after registering (L<http://developers.facebook.com/setup/>) your application on their site. Required if you'll be calling the C<request_access_token>, C<convert_sessions>, or C<authorize> methods. | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =item code | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | An authorization code string that you should have gotten by going through the C<authorize> process. | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =item postback | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | The URI that Facebook should post your authorization code back to. Required if you'll be calling the C<request_access_token> or C<authorize> methods. | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =item secret | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | The application secret that you get from Facebook after registering your application. Required if you'll be calling the C<request_access_token> or C<convert_sessions> methods. | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | =back | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =back | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =head2 uri_as_string () | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | Returns the URI that will be called to fetch the token as a string. Mostly useful for debugging and testing. | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | =head2 request () | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | Makes a request to Facebook to fetch an access token. Returns a L<Facebook::Graph::AccessToken::Response> object. | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =head2 build () | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | Checks for either access_token or code and dies if has neither. | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =head1 LEGAL | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | Facebook::Graph is Copyright 2010 - 2017 Plain Black Corporation (L<http://www.plainblack.com>) and is licensed under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =cut | ||||||||||||||||||||||||||||