| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package VKontakte::API; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
852
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
42
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
33
|
|
|
5
|
1
|
|
|
1
|
|
2117
|
use utf8; |
|
|
1
|
|
|
|
|
33
|
|
|
|
1
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
36
|
use Digest::MD5 qw(md5 md5_hex); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
482
|
|
|
8
|
1
|
|
|
1
|
|
5975
|
use WWW::Mechanize; |
|
|
1
|
|
|
|
|
320721
|
|
|
|
1
|
|
|
|
|
62
|
|
|
9
|
1
|
|
|
1
|
|
16
|
use JSON; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
13
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=pod |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
VKontakte::API - Module for login into vkontakte.ru and sending requests |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 VERSION |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Version 0.04 |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
First of all register you application at http://vkontakte.ru/apps.php?act=add |
|
28
|
|
|
|
|
|
|
get api_id and secret_key to use it like this: |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
#1. |
|
31
|
|
|
|
|
|
|
use VKontakte::API; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $vk = VKontakte::API->new('api_id', 'secret_key'); |
|
34
|
|
|
|
|
|
|
my $data=$vk->sendRequest('getProfiles', {'domains'=>'deevaas'}); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
#2. or |
|
37
|
|
|
|
|
|
|
use VKontakte::API; |
|
38
|
|
|
|
|
|
|
$vk = VKontakte::API->new( |
|
39
|
|
|
|
|
|
|
$api_id, |
|
40
|
|
|
|
|
|
|
$cgi_query->param('session[secret]'), |
|
41
|
|
|
|
|
|
|
$cgi_query->param('session[mid]'), |
|
42
|
|
|
|
|
|
|
$cgi_query->param('session[sid]') |
|
43
|
|
|
|
|
|
|
); |
|
44
|
|
|
|
|
|
|
my $data=$vk->sendRequest('getProfiles', {'domains'=>'deevaas'}); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
#3. or new one, use OAuth 2.0 |
|
48
|
|
|
|
|
|
|
use VKontakte::API::OAuth; |
|
49
|
|
|
|
|
|
|
$vk = VKontakte::API::OAuth->new( |
|
50
|
|
|
|
|
|
|
$api_id, |
|
51
|
|
|
|
|
|
|
$secret |
|
52
|
|
|
|
|
|
|
); |
|
53
|
|
|
|
|
|
|
my $data=$vk->sendRequest('getProfiles', {'domains'=>'deevaas'}); |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 new |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Create new object. Two parameters of registered application: |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=over 4 |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=item api_id |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item secret_key |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=back |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub new { |
|
73
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
74
|
0
|
|
|
|
|
|
my $self = {}; |
|
75
|
0
|
|
|
|
|
|
bless( $self, $class ); |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
$self->{api_id} = $_[0]; |
|
78
|
0
|
|
|
|
|
|
$self->{secret} = $_[1]; |
|
79
|
0
|
|
|
|
|
|
$self->{mid} = $_[2]; |
|
80
|
0
|
|
|
|
|
|
$self->{sid} = $_[3]; |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
$self->{api_url} = "http://api.vk.com/api.php"; |
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
return $self; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 sendRequest |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Send requests described at http://vkontakte.ru/developers.php?o=-1&p=%D0%9E%D0%BF%D0%B8%D1%81%D0%B0%D0%BD%D0%B8%D0%B5+%D0%BC%D0%B5%D1%82%D0%BE%D0%B4%D0%BE%D0%B2+API |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$resp = $auth->sendRequest('getProfiles', {'uids'=>'123123'}); |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=over 4 |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item method |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Name of methods listed at http://vkontakte.ru/developers.php?o=-1&p=%D0%9E%D0%BF%D0%B8%D1%81%D0%B0%D0%BD%D0%B8%D0%B5+%D0%BC%D0%B5%D1%82%D0%BE%D0%B4%D0%BE%D0%B2+API |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item params |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Parameters for method |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=back |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub sendRequest { |
|
108
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
109
|
0
|
|
|
|
|
|
my $method = $_[0]; |
|
110
|
0
|
|
|
|
|
|
my $params = $_[1]; |
|
111
|
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
$params->{'api_id'} = $self->{'api_id'}; |
|
113
|
0
|
|
|
|
|
|
$params->{'v'} = '3.0'; |
|
114
|
0
|
|
|
|
|
|
$params->{'method'} = $method; |
|
115
|
0
|
|
|
|
|
|
$params->{'timestamp'} = time(); |
|
116
|
0
|
|
|
|
|
|
$params->{'format'} = 'json'; |
|
117
|
0
|
|
|
|
|
|
$params->{'rnd'} = int(rand()*10000); |
|
118
|
|
|
|
|
|
|
|
|
119
|
0
|
0
|
|
|
|
|
my $sig = defined $self->{'mid'} ? $self->{'mid'} : ''; |
|
120
|
0
|
|
|
|
|
|
foreach my $k (sort keys %$params){ |
|
121
|
0
|
|
|
|
|
|
$sig .= $k . '=' . $params->{$k}; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
0
|
|
|
|
|
|
$sig .= $self->{secret}; |
|
124
|
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
$params->{'sig'} = md5_hex($sig); |
|
126
|
0
|
0
|
|
|
|
|
$params->{'sid'} = $self->{sid} if $self->{sid}; |
|
127
|
0
|
|
|
|
|
|
my $query = $self->{api_url} . '?' . $self->_params($params); |
|
128
|
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
my $mech = WWW::Mechanize->new( agent => 'VKontakte::API', ); |
|
130
|
0
|
|
|
|
|
|
my $r = $mech->get($query); |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# my $res = file_get_contents($query); |
|
133
|
0
|
|
|
|
|
|
my $response = $mech->content(); |
|
134
|
0
|
|
|
|
|
|
utf8::encode($response); |
|
135
|
0
|
|
|
|
|
|
return decode_json($response); |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 _params |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
prepares parameters for request |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub _params { |
|
145
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
146
|
0
|
|
|
|
|
|
my $params = shift; |
|
147
|
|
|
|
|
|
|
|
|
148
|
0
|
0
|
|
|
|
|
return unless ( ref $params eq "HASH" ); |
|
149
|
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
my @pice; |
|
151
|
0
|
|
|
|
|
|
while ( my ( $k, $v ) = each %$params ) { |
|
152
|
0
|
|
|
|
|
|
push @pice, $k . '=' . $v;# _encurl($v); |
|
153
|
|
|
|
|
|
|
} |
|
154
|
0
|
|
|
|
|
|
return join( '&', @pice ); |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 _encurl |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
encodes data for url |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=cut |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub _encurl { |
|
165
|
0
|
|
|
0
|
|
|
my ($url) = @_; |
|
166
|
0
|
0
|
|
|
|
|
( defined $url ) || ( $url = "" ); |
|
167
|
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
$url=~s/([^a-z0-9])/sprintf("%%%02x",ord($1))/egsi; |
|
|
0
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
#$url =~ s/([^a-z0-9])/sprintf("%%%x",ord($1))/egsi; |
|
170
|
0
|
|
|
|
|
|
$url =~ s/ /\+/go; |
|
171
|
0
|
|
|
|
|
|
return $url; |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 AUTHOR |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Anastasiya Deeva, C<< >> |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 BUGS |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
|
182
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
|
183
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 SUPPORT |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
perldoc VKontakte::API |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
You can also look for information at: |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=over 4 |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
L |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
L |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
L |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=item * Search CPAN |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
L |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=back |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Copyright 2011 Anastasiya Deeva. |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
226
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
|
227
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=cut |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
1; |