Esempio n. 1
0
/**
 * Returns an instance of Services_Twitter.
 *
 * @param string $ep      The endpoint to call (eg. )
 * @param bool   $auth    Whether to authenticate or not
 * @param array  $options An optional options array to pass to the 
 *                        Services_Twitter constructor
 *
 * @return Services_Twitter The twitter instance.
 */
function Services_Twitter_factory($ep, $auth = true, $options = array())
{
    //$options['raw_format'] = true;
    global $config;
    if ($auth) {
        $twitter = new Services_Twitter($config['user'], $config['pass'], $options);
    } else {
        $twitter = new Services_Twitter(null, null, $options);
    }
    if (!$config['live_test']) {
        if ($ep == 'exception1') {
            $resp = new HTTP_Request2_Response('HTTP/1.1 401 Unauthorized', false);
            $resp->appendBody('{"request":"\\/statuses\\/friends_timeline.json", ' . '"error":"Could not authenticate you."}');
        } else {
            if ($ep == 'exception2') {
                $resp = new HTTP_Request2_Response('HTTP/1.1 404 Not Found', false);
            } else {
                $resp = new HTTP_Request2_Response('HTTP/1.1 200 Success', false);
                $file = dirname(__FILE__) . '/data/' . $ep . '.dat';
                $resp->appendBody(file_get_contents($file));
            }
        }
        $mock = new HTTP_Request2_Adapter_Mock();
        $mock->addResponse($resp);
        $request = $twitter->getRequest()->setAdapter($mock);
    }
    return $twitter;
}
Esempio n. 2
0
 public function getProfileData(array $options)
 {
     try {
         $twitter = new Services_Twitter();
         $oauth = new HTTP_OAuth_Consumer($this->key, $this->secret, $this->accessToken, $this->accessTokenSecret);
         $twitter->setOAuth($oauth);
         $results = $twitter->users->show(array('user_id' => $this->twitterID));
         $data = array();
         $data['name'] = $results->name;
         $data['username'] = $results->screen_name;
         $data['description'] = $results->description;
         return $data;
     } catch (Services_Twitter_Exception $e) {
         throw new EZRP_Exception('Error getting profile data', 0, $e);
     }
 }
 protected function getTwitter()
 {
     if (!$this->twitter instanceof Services_Twitter) {
         $request = new HTTP_Request2();
         $request->setConfig(array('connect_timeout' => 1, 'timeout' => 3));
         $this->twitter = new Services_Twitter(null, null, array('format' => Services_Twitter::OUTPUT_JSON, 'use_ssl' => true));
         // Services_Twitter is set to API v1, which is dead. Remove this
         // when Services_Twitter has a new release.
         Services_Twitter::$uri = 'https://api.twitter.com/1.1';
         $this->twitter->setRequest($request);
     }
     return $this->twitter;
 }
Esempio n. 4
0
 public function loadAPI()
 {
     parent::loadAPI();
     $this->api['statuses']['update_with_media'] = new SimpleXMLElement('<endpoint name="update_with_media" method="POST" auth_required="true">
         <formats>xml,json</formats>
         <param name="status" type="string" max_length="140" required="true"/>
         <param name="media[]" type="image" required="true"/>
         <param name="possibly_sensitive" type="boolean" required="false"/>
         <param name="in_reply_to_status_id" type="integer" required="false"/>
         <param name="lat" type="lat" required="false"/>
         <param name="long" type="long" required="false"/>
         <param name="place_id" type="string" required="false"/>
         <param name="display_coordinates" type="boolean" required="false"/>
     </endpoint>');
 }
Esempio n. 5
0
<?php

require_once __DIR__ . '/../src/Sakusui.php';
require_once 'Services/Twitter.php';
require_once 'HTTP/OAuth/Consumer.php';
try {
    $twitter = new Services_Twitter();
    $oauth = new HTTP_OAuth_Consumer('consumer_key', 'consumer_secret', 'access_token', 'access_token_secret');
    $twitter->setOAuth($oauth);
    $sakusui = new Wozozo_Sakusui();
    $lunchMenus = $sakusui->getLunchMenu(new DateTime('today'));
    $twitter->statuses->update("本日のさく水ランチ:" . implode(' / ', $lunchMenus));
} catch (Services_Twitter_Exception $e) {
    echo $e->getMessage(), PHP_EOL;
}