Archive

Archive for the ‘日記’ Category

PEAR::HTTP_OAuthでxAuth

3月 5th, 2010

xAuthの申請が通ったので試してみた。

via:ウノウラボ Unoh Labs: PECL::oauthでxAuth

PHP
require_once 'HTTP/Request2.php';
require_once 'HTTP/OAuth/Consumer.php';

$consumer_key           = 'YOUR-CONSUMER-KEY';
$consumer_secret        = 'YOUR-CONSUMER-SECRET';
$username               = 'YOUR-USER-NAME';
$password               = 'YOUR-PASSWORD';
$xauth_access_token_url = 'https://api.twitter.com/oauth/access_token';

$params = array(
  'x_auth_username' => $username,
  'x_auth_password' => $password,
  'x_auth_mode'     => 'client_auth',
);

try {
  $request = new HTTP_Request2();
  $request->setConfig('ssl_verify_peer', false);

  $consumerRequest = new HTTP_OAuth_Consumer_Request();
  $consumerRequest->accept($request);

  $oauth = new HTTP_OAuth_Consumer($consumer_key, $consumer_secret);
  $oauth->accept($consumerRequest);

  $response = $oauth->sendRequest($xauth_access_token_url,
                                  $params,
                                  HTTP_Request2::METHOD_POST);

  if ($response->getStatus() !== 200) {
    throw new Exception($response->getBody(), $response->getStatus());
  }
} catch (Exception $e) {
  echo 'Error';
  exit;
}

// oauth_token=xxx&oauth_token_secret=xxx&
// user_id=xxx&screen_name=xxx&x_auth_expires=0
parse_str($response->getBody(), $access_token_info);

// oauth_token, oauth_token_secret, user_id, screen_name,
// x_auth_expires
var_dump($access_token_info);

取得したauth_tokenとtoken_secretを利用してtwitterにポスト。

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,
                                     $auth_token,
                                     $token_secret);
  $twitter->setOAuth($oauth);
  $twitter->statuses->update('なうなう');
} catch (Services_Twitter_Exception $e) {
  echo (string)$e;
  exit;
}

PHP, 日記 , ,

PHP5.3.0でsymfony1.0系でpropelコマンド実行時にエラーがでる

11月 16th, 2009

php5.3にしてからsymfony1.0系でsymfonyコマンドの一部でエラーがでるようになった。

$ ./symfony propel-build-model
....
[phingcall] Unable to return 'affix' for unknown CreoleType:

BUILD FINISHED

propelコマンドを使ってもmodelの生成ができない。

調べてみたところ、以下の方法で解決。
symfony framework forum: symfony 1.0 => Snow Leopard – longvarchar
symfony以下lib/vendor/creole/CreoleTypes.phpの39行目を以下のように修正。

PHP
        //const TEXT = 17;
        const TEXT = 30;

で、調べてみたところPHP5.3.0だとこういうことらしい。

PHP
<?php
Class Hoge
{
  const A = 1;
  const B = 1;
  public static $piyo = array(
      1 => 1,
      1 => 2,
      );
  public static $fuga = array(
      self::A => 1,
      self::B => 2,
      );
}
var_dump(Hoge::$piyo, Hoge::$fuga);

実行結果。

array(1) {
  [1]=>
  int(2)
}
array(1) {
  [1]=>
  int(1)
}

PHP5.3.0のバグ?
PHP5.3.1RC4でも変わらず。

日記

CentOSで携帯動画をストリーミングできるファイルを作成する

11月 9th, 2009

rpmforgeリポジトリを利用できるようにする。

# wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
# rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm

ffmpeg関連をインストール。
依存関係あるものをもってきたいのでffmpegもインストールするが、rpmforgeのものはaacを利用できないため、後でソースからコンパイルするので削除する。

# yum install lame faac faad2 nasm x264 xvidcore ffmpeg zlib-devel libX11-devel libXt-devel faac-devel lame-devel xvidcore-devel gcc gcc-c++
# yum remove ffmpeg

opencore-amrのインストール。
現在のffmpegだとlibamr関連が変わっている。
rpmforgeのものは0.1.1でリポジトリのffmpegに適合しないのでソースからコンパイル。

# cd /usr/local/src
# wget http://sourceforge.net/projects/opencore-amr/files/opencore-amr/0.1.2/opencore-amr-0.1.2.tar.gz/download
# tar xzf opencore-amr-0.1.2.tar.gz
# cd opencore-amr-0.1.2
#  ./configure
# make
# make install
# cd ..

共有ライブラリに認識させる。

# echo "/usr/local/lib" >> /etc/ld.so.conf.d/local.conf
# /sbin/ldconfig

ffmpegをSubversionリポジトリからインストール。
リビジョン 20483でした。

# cd /usr/local/src
# svn export svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
# cd ffmpeg
# ./configure --enable-gpl --enable-libmp3lame --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libxvid --disable-ffplay --disable-ffserver --enable-libfaac --enable-shared --enable-nonfree --prefix=/usr/local
# make
# make install
# cd ..

環境変数にLD_LIBRARY_PATHを追加。
bashrcに追加しておく。

$ echo "export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/usr/local/lib" >> ~/.bashrc
$ source ~/.bashrc

gpac(MP4Box)のインストール。
docomoストリーミングファイル作成に必要。

# cd /usr/local/src
# wget http://downloads.sourceforge.net/gpac/gpac-0.4.5.tar.gz
# tar xzf gpac-0.4.5.tar.gz
# cd gpac
# chmod u+x ./configure
# ./configure
# make lib
# make apps
# make install
# cd ..
$ ffmpeg -i video.flv -y -async 1 -vcodec mpeg4 -s 240x176 -r 14.985 -b 192 -acodec aac -ac 1 -ar 16000 -ab 80 -f 3gp docomo.3gp
$ MP4Box -add docomo.3gp -brand mmp4:1 -new docomo_str.3gp

日記

VMware ESXiでゲストOSのコピー

11月 6th, 2009

メモ

  1. コピーしたいOS(guest)の電源を落とす。
  2. コピー元と同じ構成でHDDなしの仮想マシン(clone)を新規作成する。
  3. sshでESXiにアクセスし、ディスクイメージをコピーする。
  4. 先ほど作成した仮想マシンでHDDにコピーしたディスクイメージを指定する。
  5. 仮想マシンを起動し、ネットワーク設定をする。

3のコマンド

~ # vmkfstools -i /vmfs/volumes/vmdk/guest/guest.vmdk /vmfs/volumes/vmdk/clone/clone.vmdk

日記

FreeNAS0.7RC1のftp公開ディレクトリを変更する

10月 21st, 2009

Anonymousの接続時のrootディレクトリを変更するには補助パラメータを変更する。
/mnt/share/shareをrootディレクトリにしたい場合は以下のようになる。

<Anonymous /mnt/share/share>
  User ftp
  Group wheel
  UserAlias anonymous ftp
</Anonymous>

User、Group、UserAliasは必須パラメータのようで、ないと設定が反映されなかった。

via:Anonymous

日記