The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Net::VKontakte::Standalone - Perl extension for creating standalone Vkontakte API applications

SYNOPSIS

  use Net::VKontakte::Standalone;
  my $vk = new Net::VKontakte::Standalone:: "12345678";
  my $auth_uri = $vk->auth_uri("wall,messages");

  # make the user able to enter login and password at this URI
  
  $vk->redirected($where);
  $vk->api("activity.set",{text => "playing with VK API"});

DESCRIPTION

This module is just a wrapper for some JSON parsing and WWW::Mechanize magic, not much else.

CONSTRUCTOR METHODS

$vk = Net::VKontakte::Standalone::->new($api_id);
$vk = Net::Vkontalte::Standalone::->new( key => value );

This creates the main object, sets the API ID variable (which can be got from the application management page) and creates the WWW::Mechanize object.

Possible keys:

api_id

API ID of the application, required.

errors_noauto

If true, return undef instead of automatic error handling (which includes limiting requests per second, asking for captcha and throwing exceptions). If this is a coderef, it will be called with the {error} subhash as the only argument. In both cases the error will be stored and will be accessible via $vk->error method.

captcha_handler

Should be a coderef to be called upon receiving {error} requiring CAPTCHA. The coderef will be called with the CAPTCHA URL as the only argument and should return the captcha answer (decoded to characters if needed). Works only when errors_noauto is false.

METHODS

$vk->auth_uri($scope)

This method should be called first. It returns the URI of the login page to show to the user (developer should call a browser somehow, see https://vk.com/developers.php?oid=-17680044&p=Authorizing_Client_Applications for more info).

$vk->redirected($uri)

This method should be called after a successful authorisation with the URI user was redirected to. Then the expiration time and the access token are retreived from this URI and stored in the $vk object.

$vk->api($method,{parameter => "value", parameter => "value" ...})

This method calls the API methods on the server, as described on https://vk.com/developers.php?oid=-17680044&p=Making_Requests_to_API. Resulting JSON is parsed and returned as a hash reference.

$vk->captcha_handler($sub)

Sets the sub to call when CAPTCHA needs to be entered. Works only when errors_noauto is false.

$vk->error

Returns the last {error} subhash received (if errors_nonfatal is true).

$vk->errors_noauto

If true, return undef instead of automatic handling API error. If this is a coderef, it will be called with the {error} subhash as the only argument. In both cases the error will be stored and will be accessible via $vk->error method.

BUGS

Probably many. Feel free to report my mistakes and propose changes.

Currently there is no test suite.

SEE ALSO

https://vk.com/developers.php for the list of methods and how to use them.

AUTHOR

Krylov Ivan, <krylov.r00t@gmail.com>

COPYRIGHT AND LICENSE

Copyright (C) 2012 by Krylov Ivan

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.2 or, at your option, any later version of Perl 5 you may have available.