1
我用Twitter註冊了一個應用程序。我使用Net :: Twitter :: OAuth來管理與Twitter的交互。爲什麼我無法使用Net :: Twitter :: OAuth獲得Twitter寫入訪問權限?
我設法重定向用戶,允許他在他的Twitter帳戶中安裝應用程序。該應用程序安裝有讀取&寫入權限。我有閱讀權限,但是我沒有設法爲他發送任何推文:Twitter返回該通話未經授權。
我正在使用自己的Twitter帳戶進行測試。
這裏是我使用的代碼(Perl的&催化劑):
# step 1: Redirect user to Twitter
my $client = Net::Twitter::OAuth->new(
traits => ['OAuth'],
consumer_key => Bargain->config->{'consumer_key'},
consumer_secret => Bargain->config->{'consumer_secret'},
);
my $url = $client->oauth->get_authorization_url({ callback => $callback_url});
$c->response->cookies->{oauth} = {
value => {
token => $client->request_token,
token_secret => $client->request_token_secret,
},
};
$c->response->redirect($url);
# step 2 - After installing the app, Twitter redirects the user here
my $verifier = $c->req->params->{oauth_verifier};
my $oauth_token = $c->req->params->{oauth_token};
$client->request_token($client->request_token);
$client->request_token_secret($client->request_token_secret);
my($access_token, $access_token_secret) =
$client->request_access_token(verifier => $verifier);
# step 3 - With all the info, Access suer account
my $nt = Net::Twitter::OAuth->new(
traits => ['OAuth'], # 'API::REST',
consumer_key => Bargain->config->{'consumer_key'},
consumer_secret => Bargain->config->{'consumer_secret'},
);
$nt->access_token($access_token);
$nt->access_token_secret($access_token_secret);
if ($nt->authorized) {
print "Authorized, sending tweets\n";
print $nt->friends_timeline, "\n"; # OK
$nt->update('First example'); # Does not work
}
任何想法,我缺少的,或者什麼,我做錯了什麼?
Thnaks,它似乎工作。我如何獲得用戶ID?它需要獲得用戶狀態,但我沒有看到任何函數獲取id /用戶名 – Julien 2009-08-02 05:35:38