SlideShare una empresa de Scribd logo
1 de 31
Jul 2010
CakePHP
•   Twitter API
    •   OAuth


•   TwitterKit
    •   TwitterKit
    •   TwitterKit
About Me



•   WEB Developer / PHP / CakePHP / HTML / CSS / jQuery / PostgreSQL / MySQL /
    iPhone / /     /      /   /      /               /             / no more

•   BLOG: http://php-tips.com/
•   TWITTER: @nojimage
Twitter API
Twitter API

•   http://api.twitter.com/        HTTP
    JSON     XML
    ‣

    ‣

    ‣

    ‣                  etc...


•
•                  http://dev.twitter.com/
OAuth

•   Twitter API                     Basic   OAuth
    ‣   Basic


•   ConsumerKey AccessToken
    ‣

    ‣   Twitter   AccessToken


•                 dev.twitter.com
OAuth

•                       Twitter
    ‣   ConsumerKey               RequestToken Twitter
    ‣   Authorize URL        ←


•              Twitter

•                       Twitter
    ‣                        URL        (oauth_token, oauth_verifier)
    ‣                   RequestToken                      AccessToken Twitter
    ‣   AccessToken ConsumerKey                     API
TwitterKit
TwitterKit

•   TwitterAPI
    ‣   DataSource, Behavior, Component
    ‣   Twitter

•
    ‣   PHP 5.2 upper (json_encode/json_decode)
    ‣   CakePHP 1.3 +
    ‣   jQuery 1.4.2 +

                   http://github.com/elstc/twitter_kit
TwitterKit

•   Twitter API
    ‣                      http://openlist.jp/
    ‣                     http://tsuketter.com/ (                                 )


•              pear HTTP_OAuth
    ‣   pear                                        Neil Crookess(@neilcrookes)
        HttpSocketOauth


•   OAuth
•


•
•


•
•   http://dev.twitter.com/apps/new

    ‣


    ‣   callback localhost



    ‣

          Read Write
•   http://dev.twitter.com/apps/{app_id}

    •                 Consumer Key   Consumer Secret



    •         My Access Token
        AccessToken
TwitterKit Install

•                           [git clone]
    cd app/plugins
    git clone http://github.com/elstc/twitter_kit.git

    ‣   git               github


•   DB                   [cake schema]
    cake/console/cake schema create TwitterKit.TwitterKit

    ‣            Enter
database.php

•   ConsumerKey, ConsumerSecret, CallbackURL
    <?php
    class DATABASE_CONFIG {

      var $default = array(
    
  
   // DB        .....
        );

        var   $twitter = array( //                                     twitter
             'driver' => 'TwitterKit.TwitterSource',
             'oauth_consumer_key' => '{YOUR_CONSUMER_KEY}',
             'oauth_consumer_secret' => '{YOUR_CONSUMER_SECRET}',
             'oauth_callback'      => '/twitter_kit/oauth/callback',
             'cache' => true, // app/tmp/cache/twitter/
        );
    }
Model

•   Behavior
    <?php
    class Tiwt extends AppModel {

        var $name = 'Tiwt';

        var $useTable = false; //

        //                           TwitterTweetBehavior
        var $actsAs = array('TwitterKit.TwitterTweet');

    }
Controller

•   Component, Helper
    <?php
    class TiwtsController extends AppController {

        var $name = 'Tiwts';

        //
        var $components = array('TwitterKit.Twitter');

        //                      TwitterFormHelper
        var $helpers = array('TwitterKit.TwitterForm');

    }
AuthComponent

•   AppController::beforeFilter()
    <?php
    class AppController extends Controller {

      var $components = array('Session', 'Auth');

      // ...

      public function beforeFilter() {
           $this->Auth->authorize = 'controller';
           $this->Auth->userModel = 'TwitterKit.TwitterKitUser';
           $this->Auth->loginAction = array(
              'plugin' => 'twitter_kit',
              'controller' => 'users', 'action' => 'login');
      }

      // ...
AuthComponent

•   isAuthorized                               AccessToken
    <?php
    class AppController extends Controller {

     // ...

     public function isAuthorized() {
        // set OAuth
              ConnectionManager::getDatasource('twitter')->setToken(
                 $this->Auth->user('oauth_token'),
                 $this->Auth->user('oauth_token_secret')
              );
          // ...
          return true;
      }

      // ...
Action!

•   TwitController::index()
    •   HOME
    •   Model fetch


•   TwitController::add()
    •   POST
    •   Model teewt
    •
TiwtsController::index()
function index() {

    if ($this->Session->read('reflash')) {
        //
        $this->Twitter->refreshCache();
    }

    $timelines = $this->Tiwt->fetch($this->params['named']);
    $this->set(compact('timelines'));

}
Tiwt::fetch()
function fetch($options = array()) {

    $params = array();

    foreach (array('since_id', 'max_id', 'count', 'page') as $key) {
       if (!empty($options[$key])) {
           $params[$key] = $options[$key];
       }
    }

    //
    $results = $this->getTwitterSource()->statuses_home_timeline($params);
    if (empty($results)) { return array(); }
    //
    return array_map(array($this, '_reverse'), $results);
}
TiwtsController::add()
function add() {

    $this->autoRender = false;

    if (!empty($this->data)) {

        if ( $this->Tiwt->teewt($this->data) ) {
            $this->Session->write('reflash', true); //
            $this->Session->setFlash($this->Tiwt->strrev('          '));
        } else {
           $this->Session->setFlash($this->Tiwt->strrev('    '));
        }

    }

    $this->redirect(array('action' => 'index'));

}
Tiwt::teewt()
function teewt($data = null) {

    if (empty($data)) { $data = $this->data; }

    //         (tweet             TwitterKit::TwitterTweet   )

    return $this->tweet($this->strrev($data[$this->alias]['text']));

}
Tiwt::strrev(), Tiwt::_reverse()
function _reverse($data) {

    if (empty($data)) { return array(); }

    $data['rev']['text'] = $this->strrev($data['text']);
    $data['rev']['user']['screen_name'] = $this->strrev(
      $data['user']['screen_name']);

    return $data;

}

function strrev($str){

    preg_match_all('/./us', $str, $ar);
    return join('', array_reverse($ar[0]));

}
View

•   layout/default.ctp
    •   jQuery


•   tiwts/index.ctp
    •                 → TwitterFormHelper::tweet()
    •
http://tiwt.php-tips.com/
•   Twitter



•   TwitterKit
                 github PULL
TwitterKitではじめる OAuthスピードクッキング

Más contenido relacionado

La actualidad más candente

優しいWAFの作り方
優しいWAFの作り方優しいWAFの作り方
優しいWAFの作り方techmemo
 
How to develop modern web application framework
How to develop modern web application frameworkHow to develop modern web application framework
How to develop modern web application frameworktechmemo
 
With a Mighty Hammer
With a Mighty HammerWith a Mighty Hammer
With a Mighty HammerBen Scofield
 
Storytelling By Numbers
Storytelling By NumbersStorytelling By Numbers
Storytelling By NumbersMichael King
 
New Symfony Tips & Tricks (SymfonyCon Paris 2015)
New Symfony Tips & Tricks (SymfonyCon Paris 2015)New Symfony Tips & Tricks (SymfonyCon Paris 2015)
New Symfony Tips & Tricks (SymfonyCon Paris 2015)Javier Eguiluz
 
Symfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worldsSymfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worldsIgnacio Martín
 
Design how your objects talk through mocking
Design how your objects talk through mockingDesign how your objects talk through mocking
Design how your objects talk through mockingKonstantin Kudryashov
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the FinishYehuda Katz
 
Get into the FLOW with Extbase
Get into the FLOW with ExtbaseGet into the FLOW with Extbase
Get into the FLOW with ExtbaseJochen Rau
 
Incremental Type Safety in React Apollo
Incremental Type Safety in React Apollo Incremental Type Safety in React Apollo
Incremental Type Safety in React Apollo Evans Hauser
 
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017Ryan Weaver
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony AppsKris Wallsmith
 
Introduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingIntroduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingSamuel ROZE
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Michelangelo van Dam
 
Guard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful SecurityGuard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful SecurityRyan Weaver
 
Алексей Плеханов: Новинки Laravel 5
Алексей Плеханов: Новинки Laravel 5Алексей Плеханов: Новинки Laravel 5
Алексей Плеханов: Новинки Laravel 5Oleg Poludnenko
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 

La actualidad más candente (20)

優しいWAFの作り方
優しいWAFの作り方優しいWAFの作り方
優しいWAFの作り方
 
How to develop modern web application framework
How to develop modern web application frameworkHow to develop modern web application framework
How to develop modern web application framework
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
With a Mighty Hammer
With a Mighty HammerWith a Mighty Hammer
With a Mighty Hammer
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Storytelling By Numbers
Storytelling By NumbersStorytelling By Numbers
Storytelling By Numbers
 
Complex Sites with Silex
Complex Sites with SilexComplex Sites with Silex
Complex Sites with Silex
 
New Symfony Tips & Tricks (SymfonyCon Paris 2015)
New Symfony Tips & Tricks (SymfonyCon Paris 2015)New Symfony Tips & Tricks (SymfonyCon Paris 2015)
New Symfony Tips & Tricks (SymfonyCon Paris 2015)
 
Symfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worldsSymfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worlds
 
Design how your objects talk through mocking
Design how your objects talk through mockingDesign how your objects talk through mocking
Design how your objects talk through mocking
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
Get into the FLOW with Extbase
Get into the FLOW with ExtbaseGet into the FLOW with Extbase
Get into the FLOW with Extbase
 
Incremental Type Safety in React Apollo
Incremental Type Safety in React Apollo Incremental Type Safety in React Apollo
Incremental Type Safety in React Apollo
 
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
 
Introduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingIntroduction to CQRS and Event Sourcing
Introduction to CQRS and Event Sourcing
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
 
Guard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful SecurityGuard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful Security
 
Алексей Плеханов: Новинки Laravel 5
Алексей Плеханов: Новинки Laravel 5Алексей Плеханов: Новинки Laravel 5
Алексей Плеханов: Новинки Laravel 5
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 

Destacado

OAuth Echo の Rails Gem
OAuth Echo の Rails GemOAuth Echo の Rails Gem
OAuth Echo の Rails GemToru Kawamura
 
セキュリティとコンプライアンスプログラムについて
セキュリティとコンプライアンスプログラムについてセキュリティとコンプライアンスプログラムについて
セキュリティとコンプライアンスプログラムについてToshiboumi Ohta
 
Hyman Charme 09 11 09 Final 1
Hyman Charme 09 11 09 Final 1Hyman Charme 09 11 09 Final 1
Hyman Charme 09 11 09 Final 1guest7f6f4c6
 
Girls Day Out Giving Project 2009
Girls Day Out Giving Project 2009Girls Day Out Giving Project 2009
Girls Day Out Giving Project 2009jwinzenried
 
Composerはじめました
ComposerはじめましたComposerはじめました
ComposerはじめましたTakashi Nojima
 

Destacado (8)

OAuth Echo の Rails Gem
OAuth Echo の Rails GemOAuth Echo の Rails Gem
OAuth Echo の Rails Gem
 
セキュリティとコンプライアンスプログラムについて
セキュリティとコンプライアンスプログラムについてセキュリティとコンプライアンスプログラムについて
セキュリティとコンプライアンスプログラムについて
 
Hyman Charme 09 11 09 Final 1
Hyman Charme 09 11 09 Final 1Hyman Charme 09 11 09 Final 1
Hyman Charme 09 11 09 Final 1
 
セキュそば 090314
セキュそば 090314セキュそば 090314
セキュそば 090314
 
Girls Day Out Giving Project 2009
Girls Day Out Giving Project 2009Girls Day Out Giving Project 2009
Girls Day Out Giving Project 2009
 
FabricとRailsと私
FabricとRailsと私FabricとRailsと私
FabricとRailsと私
 
Plugin for CakePHP2.0
Plugin for CakePHP2.0Plugin for CakePHP2.0
Plugin for CakePHP2.0
 
Composerはじめました
ComposerはじめましたComposerはじめました
Composerはじめました
 

Similar a TwitterKitではじめる OAuthスピードクッキング

Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)danwrong
 
An introduction to Laravel Passport
An introduction to Laravel PassportAn introduction to Laravel Passport
An introduction to Laravel PassportMichael Peacock
 
Building TweetEngine
Building TweetEngineBuilding TweetEngine
Building TweetEngineikailan
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Michelangelo van Dam
 
Let's read code: the python-requests library
Let's read code: the python-requests libraryLet's read code: the python-requests library
Let's read code: the python-requests librarySusan Tan
 
Designing CakePHP plugins for consuming APIs
Designing CakePHP plugins for consuming APIsDesigning CakePHP plugins for consuming APIs
Designing CakePHP plugins for consuming APIsNeil Crookes
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐいHisateru Tanaka
 
Workshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastWorkshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastMichelangelo van Dam
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Michelangelo van Dam
 
Twig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPTwig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPFabien Potencier
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Michelangelo van Dam
 
Motion Django Meetup
Motion Django MeetupMotion Django Meetup
Motion Django MeetupMike Malone
 
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rulesSrijan Technologies
 
YDN KR Tech Talk : Pipes 와 YQL 활용하기
YDN KR Tech Talk : Pipes 와 YQL 활용하기YDN KR Tech Talk : Pipes 와 YQL 활용하기
YDN KR Tech Talk : Pipes 와 YQL 활용하기Jinho Jung
 

Similar a TwitterKitではじめる OAuthスピードクッキング (20)

Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)
 
An introduction to Laravel Passport
An introduction to Laravel PassportAn introduction to Laravel Passport
An introduction to Laravel Passport
 
Building TweetEngine
Building TweetEngineBuilding TweetEngine
Building TweetEngine
 
Api
ApiApi
Api
 
Twitter4R OAuth
Twitter4R OAuthTwitter4R OAuth
Twitter4R OAuth
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
Let's read code: the python-requests library
Let's read code: the python-requests libraryLet's read code: the python-requests library
Let's read code: the python-requests library
 
Designing CakePHP plugins for consuming APIs
Designing CakePHP plugins for consuming APIsDesigning CakePHP plugins for consuming APIs
Designing CakePHP plugins for consuming APIs
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Workshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastWorkshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfast
 
Lecture n
Lecture nLecture n
Lecture n
 
Language literacy
Language literacyLanguage literacy
Language literacy
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013
 
Mining Georeferenced Data
Mining Georeferenced DataMining Georeferenced Data
Mining Georeferenced Data
 
Twig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPTwig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHP
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
 
Motion Django Meetup
Motion Django MeetupMotion Django Meetup
Motion Django Meetup
 
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
 
Cakephpstudy5 hacks
Cakephpstudy5 hacksCakephpstudy5 hacks
Cakephpstudy5 hacks
 
YDN KR Tech Talk : Pipes 와 YQL 활용하기
YDN KR Tech Talk : Pipes 와 YQL 활용하기YDN KR Tech Talk : Pipes 와 YQL 활용하기
YDN KR Tech Talk : Pipes 와 YQL 활용하기
 

Último

JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuidePixlogix Infotech
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Hiroshi SHIBATA
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfSrushith Repakula
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfFIDO Alliance
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024Stephen Perrenod
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsLeah Henrickson
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceSamy Fodil
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxFIDO Alliance
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...ScyllaDB
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxjbellis
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfalexjohnson7307
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Patrick Viafore
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераMark Opanasiuk
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...FIDO Alliance
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptxFIDO Alliance
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxFIDO Alliance
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctBrainSell Technologies
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...FIDO Alliance
 
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdfMuhammad Subhan
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentationyogeshlabana357357
 

Último (20)

JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptx
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdf
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 

TwitterKitではじめる OAuthスピードクッキング

  • 2. Twitter API • OAuth • TwitterKit • TwitterKit • TwitterKit
  • 3. About Me • WEB Developer / PHP / CakePHP / HTML / CSS / jQuery / PostgreSQL / MySQL / iPhone / / / / / / / / no more • BLOG: http://php-tips.com/ • TWITTER: @nojimage
  • 5. Twitter API • http://api.twitter.com/ HTTP JSON XML ‣ ‣ ‣ ‣ etc... • • http://dev.twitter.com/
  • 6. OAuth • Twitter API Basic OAuth ‣ Basic • ConsumerKey AccessToken ‣ ‣ Twitter AccessToken • dev.twitter.com
  • 7. OAuth • Twitter ‣ ConsumerKey RequestToken Twitter ‣ Authorize URL ← • Twitter • Twitter ‣ URL (oauth_token, oauth_verifier) ‣ RequestToken AccessToken Twitter ‣ AccessToken ConsumerKey API
  • 9. TwitterKit • TwitterAPI ‣ DataSource, Behavior, Component ‣ Twitter • ‣ PHP 5.2 upper (json_encode/json_decode) ‣ CakePHP 1.3 + ‣ jQuery 1.4.2 + http://github.com/elstc/twitter_kit
  • 10. TwitterKit • Twitter API ‣ http://openlist.jp/ ‣ http://tsuketter.com/ ( ) • pear HTTP_OAuth ‣ pear Neil Crookess(@neilcrookes) HttpSocketOauth • OAuth
  • 11.
  • 14. http://dev.twitter.com/apps/new ‣ ‣ callback localhost ‣ Read Write
  • 15. http://dev.twitter.com/apps/{app_id} • Consumer Key Consumer Secret • My Access Token AccessToken
  • 16. TwitterKit Install • [git clone] cd app/plugins git clone http://github.com/elstc/twitter_kit.git ‣ git github • DB [cake schema] cake/console/cake schema create TwitterKit.TwitterKit ‣ Enter
  • 17. database.php • ConsumerKey, ConsumerSecret, CallbackURL <?php class DATABASE_CONFIG { var $default = array( // DB ..... ); var $twitter = array( // twitter 'driver' => 'TwitterKit.TwitterSource', 'oauth_consumer_key' => '{YOUR_CONSUMER_KEY}', 'oauth_consumer_secret' => '{YOUR_CONSUMER_SECRET}', 'oauth_callback' => '/twitter_kit/oauth/callback', 'cache' => true, // app/tmp/cache/twitter/ ); }
  • 18. Model • Behavior <?php class Tiwt extends AppModel { var $name = 'Tiwt'; var $useTable = false; // // TwitterTweetBehavior var $actsAs = array('TwitterKit.TwitterTweet'); }
  • 19. Controller • Component, Helper <?php class TiwtsController extends AppController { var $name = 'Tiwts'; // var $components = array('TwitterKit.Twitter'); // TwitterFormHelper var $helpers = array('TwitterKit.TwitterForm'); }
  • 20. AuthComponent • AppController::beforeFilter() <?php class AppController extends Controller { var $components = array('Session', 'Auth'); // ... public function beforeFilter() { $this->Auth->authorize = 'controller'; $this->Auth->userModel = 'TwitterKit.TwitterKitUser'; $this->Auth->loginAction = array( 'plugin' => 'twitter_kit', 'controller' => 'users', 'action' => 'login'); } // ...
  • 21. AuthComponent • isAuthorized AccessToken <?php class AppController extends Controller { // ... public function isAuthorized() { // set OAuth ConnectionManager::getDatasource('twitter')->setToken( $this->Auth->user('oauth_token'), $this->Auth->user('oauth_token_secret') ); // ... return true; } // ...
  • 22. Action! • TwitController::index() • HOME • Model fetch • TwitController::add() • POST • Model teewt •
  • 23. TiwtsController::index() function index() { if ($this->Session->read('reflash')) { // $this->Twitter->refreshCache(); } $timelines = $this->Tiwt->fetch($this->params['named']); $this->set(compact('timelines')); }
  • 24. Tiwt::fetch() function fetch($options = array()) { $params = array(); foreach (array('since_id', 'max_id', 'count', 'page') as $key) { if (!empty($options[$key])) { $params[$key] = $options[$key]; } } // $results = $this->getTwitterSource()->statuses_home_timeline($params); if (empty($results)) { return array(); } // return array_map(array($this, '_reverse'), $results); }
  • 25. TiwtsController::add() function add() { $this->autoRender = false; if (!empty($this->data)) { if ( $this->Tiwt->teewt($this->data) ) { $this->Session->write('reflash', true); // $this->Session->setFlash($this->Tiwt->strrev(' ')); } else { $this->Session->setFlash($this->Tiwt->strrev(' ')); } } $this->redirect(array('action' => 'index')); }
  • 26. Tiwt::teewt() function teewt($data = null) { if (empty($data)) { $data = $this->data; } // (tweet TwitterKit::TwitterTweet ) return $this->tweet($this->strrev($data[$this->alias]['text'])); }
  • 27. Tiwt::strrev(), Tiwt::_reverse() function _reverse($data) { if (empty($data)) { return array(); } $data['rev']['text'] = $this->strrev($data['text']); $data['rev']['user']['screen_name'] = $this->strrev( $data['user']['screen_name']); return $data; } function strrev($str){ preg_match_all('/./us', $str, $ar); return join('', array_reverse($ar[0])); }
  • 28. View • layout/default.ctp • jQuery • tiwts/index.ctp • → TwitterFormHelper::tweet() •
  • 30. Twitter • TwitterKit github PULL

Notas del editor