Skip to content

Net::Twitch::Oauth2 - a simple Perl wrapper around Twitch OAuth v2.0 protocol

License

Notifications You must be signed in to change notification settings

RJReed67/Net-Twitch-Oauth2

Repository files navigation

NAME

Net::Twitch::Oauth2 - a simple Perl wrapper around Twitch OAuth v2.0 protocol

SYNOPSIS

use CGI;
my $cgi = CGI->new;
 
use Net::Twitch::Oauth2;
 
my $twitch = Net::Twitch::Oauth2->new(
    application_id => 'your_application_id', 
    application_secret => 'your_application_secret',
    callback => 'http://yourdomain.com/twitch/callback'
);
 
###get authorization URL for your application
my $url = $twitch->get_authorization_url(
    scope => ['user_read'],
);
 
####now redirect to this url
print $cgi->redirect($url);
 
##once user authorizes your application twitch 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 $twitch = Net::Twitch::Oauth2->new(
    application_id => 'your_application_id',
    application_secret => 'your_application_secret',
    callback => 'http://yourdomain.com/twitch/callback'
);
 
my $access_token = $twitch->post_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 twitch on behalf of this user
 
my $twitch = Net::Twitch::Oauth2->new(
    access_token => $access_token
);
 
my $info = $twitch->get(
    'https://api.twitch.tv/kraken/user' ##Twitch API URL
);
 
print $info->as_json;
 

DESCRIPTION

Net::Twitch::Oauth2 gives you a way to simply access Twitch.tv Oauth 2.0 protocol

For more information please see example folder shipped with this Module

SEE ALSO

For more information about Twitch Oauth 2.0 API

Please Check http://dev.twitch.tv

USAGE

Net::Twitch::Oauth2->new( %args )

Pass args as hash. %args are:

  • application_id

    Your application id as you get from twitch developers platform when you register your application

  • application_secret

    Your application secret id as you get from twitch developers platform when you register your application

$twitch->get_authorization_url( %args )

Return an Authorization URL for your application, once you receive this URL redirect user there in order to authorize your application

  • scope

    ['user_read',...]

    Array of Extended permissions as described by twitch Oauth2.0 API you can get more information about scope/Extended Permission from http://dev.twitch.tv

  • callback

    callback URL, where twitch will send users after they authorize your application

$twitch->post_access_token( %args )

Returns access_token string One arg to pass

  • code

    This is the verifier code that twitch sends back to your callback URL once user authorize your app, you need to capture this code and pass to this method in order to get access_token

    Verifier code will be presented with your callback URL as code parameter as the following

    http://your-call-back-url.com?code=234er7y6fdgjdssgfsd...

    When access token is returned you need to save it in a secure place in order to use it later in your application

$twitch->get( $url,$args )

Send get request to twitch and returns response back from twitch

  • url

    Twitch API URL as string

  • $args

    hashref of parameters to be sent with graph API URL if required

The response returned can be formatted as the following

  • $response>as_json

    Returns response as json object

  • $response>as_hash

    Returns response as perl hashref

For more information about twitch API, please check http://dev.twitch.tv

$twitch->post( $url,$args )

Send post request to twitch API, usually to post something

  • url

    Twitch API URL as string

  • $args

    hashref of parameters to be sent with twitch API URL

For more information about twitch API, please check http://dev.twitch.tv

INSTALLATION

To install this module type the following:

perl Makefile.PL
make
make test
make install
 

DEPENDENCIES

This module requires these other modules and libraries:

Jason::Any
LWP::UserAgent
URI::Escape
 

AUTHOR

Ronald J. Reed, <[email protected]> Based on Net::Facebook::Oauth2 module by Mahmoud A. Mehyar, <[email protected]>

COPYRIGHT AND LICENSE

Copyright (C) 2014 by Ronald J. Reed

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

POD ERRORS

Hey! The above document had some coding errors, which are explained below:

Around line 108:

=back without =over

About

Net::Twitch::Oauth2 - a simple Perl wrapper around Twitch OAuth v2.0 protocol

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages