Skip to content

Instantly share code, notes, and snippets.

@nitriques
Created June 23, 2015 20:03
Show Gist options
  • Save nitriques/f59db0af0c1b88c2a9ba to your computer and use it in GitHub Desktop.
Save nitriques/f59db0af0c1b88c2a9ba to your computer and use it in GitHub Desktop.

Revisions

  1. nitriques created this gist Jun 23, 2015.
    42 changes: 42 additions & 0 deletions data.twitter.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    <?php

    require_once(EXTENSIONS . '/remote_datasource/data-sources/datasource.remote.php');

    Class datasourcetwitter extends RemoteDatasource {

    public $dsParamROOTELEMENT = 'twitter';
    public $dsParamURL = 'https://api.twitter.com/1.1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=ACCOUNT_NAME&count=10';
    public $dsParamFORMAT = 'json';
    public $dsParamXPATH = '/';
    public $dsParamCACHE = 30;
    public $dsParamTIMEOUT = 10;

    public static function prepareGateway(&$ch) {
    // to generate bearer token, create and app at https://apps.twitter.com/
    // aand then go to http://twitter-bearer-token.herokuapp.com/
    $ch->setopt('HTTPHEADER',array('Content-Type: application/x-www-form-urlencoded;charset=UTF-8'));
    $ch->setopt('HTTPHEADER',array('Authorization: Bearer AAAAAAAAAAAAAAAAAAAAAIu%2FfgAAAAAAK7adp...'));
    }

    public function __construct($env=NULL, $process_params=true){
    parent::__construct($env, $process_params);
    $this->_dependencies = array();
    }

    public function about(){
    return array(
    'name' => 'Twitter',
    'author' => array(
    'name' => 'Your name',
    'website' => 'http://example.com',
    'email' => '[email protected]'),
    'version' => 'Symphony 2.6.1',
    'release-date' => '2015-05-13T14:30:04+00:00'
    );
    }

    public function allowEditorToParse(){
    return true;
    }

    }