El gráfico de Facebook de Perl no se pudo recuperar el token de acceso: solicitud incorrecta en /usr/local/share/perl/5.10.1/Facebook/Graph/AccessToken/Response.pm

I am trying to get access token but getting error as

Bad Request at /usr/local/share/perl/5.10.1/Facebook/Graph/AccessToken/Response.pm line 26

El siguiente es el código

use Facebook::Graph                                     ;

 my $fb = Facebook::Graph->new(
     app_id          => $facebook_app_id,
     secret          => $facebook_app_secret,
     postback        => $postback_url,

   );

 my $uri = $fb
    ->authorize
    ->extend_permissions(qw(offline_access publish_stream))
    ->uri_as_string;

It is successful redirecting to postback url and i am getting code from get paramater

my code in postback url / page

use Facebook::Graph                                     ;

my $fb = Facebook::Graph->new(
     app_id          => $facebook_app_id,
     secret          => $facebook_app_secret,
     postback        => $postback_url,

    );

when i am doing $fb->request_access_token( $code ) ;

I am getting error as Could not fetch access token: Bad Request at /usr/local/share/perl/5.10.1/Facebook/Graph/AccessToken/Response.pm line 26

please help Thanks in advance.

preguntado el 09 de marzo de 12 a las 13:03

The Facebook::Graph module and its siblings are quite new modules. The author has done a good job with them though, and they're deployed in a real-world business application. Given how new they are, the person most likely to be able to answer questions on them is the author. You may look up his email address in the POD and get in touch with him. I've seen his presentation on Facebook::Graph at the Los Angeles PerlMongers and believe he's receptive. -

Can you please show your complete code and error trace? I used your two snippets successfully. -

1 Respuestas

I used your first snippet to generate a code using my own application.

After manually getting a code:

#!/usr/bin/perl
use strict;
use warnings;
my $facebook_app_id =     'MYAPP';
my $facebook_app_secret = 'SECRET'
my $postback_url =        'http://localhost:8321/';
my $code =                '...';

use Facebook::Graph;
use Data::Dumper;

my $fb = Facebook::Graph->new(
   app_id          => $facebook_app_id,
   secret          => $facebook_app_secret,
   postback        => $postback_url,
);
print Dumper $fb->request_access_token($code);

This dumped out the expected json repsonse with 'token' => '...tokenval...'

I was able to recreate the error you posted by modifying the postback to any value other than that used when creating the code. This includes adding or removing the trailing slash. So make sure your postback url matches!!

Could not fetch access token: Bad Request at /Users/andrew/perl5/lib/perl5/Facebook/Graph/AccessToken/Response.pm line 26.

Similarly, if you hold onto the $code for too long it will expire. Then you must create a new one. You can save/cache the access_token devuelto por request_access_token. They don't last very long, but you can request a longer lived one with the recent facebook api changes.

respondido 14 nov., 12:19

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.