facebook twitter hatena line email

Php/twitter/twitteroauth

提供: 初心者エンジニアの簡易メモ
移動: 案内検索

twitteroauthダウンロード

https://github.com/abraham/twitteroauth

$ git clone https://github.com/abraham/twitteroauth twitteroauth

twitterへ投稿&tweet取得

<?php
require_once 'twitteroauth/twitteroauth/twitteroauth.php';
require_once 'twitteroauth/twitteroauth/OAuth.php';
//オプション設定
$options = array('p' => 'testword', 'count'=>'5','lang'=>'ja');
$twitter = new TwitterOAuth(
               $dummy, //Consumer Key
               $dummy, //Consumer Secret
               $dummy, //Access Token
               $dummy //Access Token Secret
);
$json = $twitter->OAuthRequest(
    'https://api.twitter.com/1.1/search/tweets.json',
    'GET',
    $options
);
$status = $twitter->post('statuses/update', array('status' => $msg));
$data = json_decode($json, true);
foreach ($data['statuses'] as $result){
   $id = $result['id'];
   $name = $result['in_reply_to_screen_name'];
   $uri = "http://twitter.com/".$name;
   $link = $result['user']['profile_image_url'];
   $content = $result['text'];
   $updated = $result['created_at'];
   $jptime = strtotime($updated);
   $timestamp = $jptime + 9 * 60 * 60;
   $timestamp = date("Y-m-d H:i:s",$timestamp);
   $tmpHtml .= $content."<hr>";
}

Zend_AutoLoaderがかかってる場合は以下のようなエラーが出る

PHP Warning:  include_once(OAuthException.php): failed to open stream: No such file or directory in /usr/share/php/ZendFramework-1.12.3-minimal/library/Zend/Loader.php on line 134
library直下などにOAuthException.phpを用意する
  • library/OAuthException.php
<?php
class OAuthException extends Exception{}