1

我尝试从应用程序的用户那里获取一些详细信息,但是遇到了问题,因为我在下面运行此代码后不知道如何处理我得到的代码,我得到如下信息:

http://myapp.com/?code=AQAPYR33UZrJpuPrAfE_lL3XPCBaw1ZcTLRl_9cYU2H77T7S3VKVz0njBt_0Jff54HfrzHW9_r-WF_-GN1VWHjEi9zNIMHZHFSEqXcTD7vbP2HKqN1DaEAealNxBNpATFb-RAFYIAZL4EqSUXLCYJ9-WvvDF5oWCUd5vAQ3TiXgPUDWml35v43fBn2xXJo1

我认为它的访问令牌,但它没有......

   use CGI;
my $cgi = CGI->new;

use Net::Facebook::Oauth2;

my $fb = Net::Facebook::Oauth2->new(
    application_id => 'your_application_id', 
    application_secret => 'your_application_secret',
    callback => 'myapp.com'
);

###get authorization URL for your application
my $url = $fb->get_authorization_url(
    scope => ['offline_access','publish_stream'],
    display => 'page'
);

####now redirect to this url
print $cgi->redirect($url);

##once user authorizes your application facebook will send him/her back to your application
##to the callback link provided above

###in your callback block capture verifier code and get access_token

my $fb = Net::Facebook::Oauth2->new(
    application_id => 'your_application_id',
    application_secret => 'your_application_secret',
    callback => 'http://myapp.com'
);

my $access_token = $fb->get_access_token(code => $cgi->param('code'));
###save this token in database or session

##later on your application you can use this verifier code to comunicate
##with facebook on behalf of this user

my $fb = Net::Facebook::Oauth2->new(
    access_token => $access_token
);

my $info = $fb->get(
    'https://graph.facebook.com/me' ##Facebook API URL
);

print $info->as_json;
4

0 回答 0