기타 개발관련2013. 7. 3. 11:49


1. 어플리케이션 생성

https://dev.twitter.com/apps 에서 새로운 어플리케이션 생성. 

 Details 탭에서 create my access token 으로 토큰 생성

 

 

2. 트윗 가져오기 예제

index.php

 

<?php

ini_set('display_errors', 1);
require_once('TwitterAPIExchange.php');

/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
    'oauth_access_token' => "Access token",
    'oauth_access_token_secret' => "Access token secret",
    'consumer_key' => "Consumer key",
    'consumer_secret' => "Consumer secret"
);

// 트윗 종류 및 옵션등의 확인 => https://dev.twitter.com/docs/api/1.1

$url='https://api.twitter.com/1.1/statuses/home_timeline.json';
$getfield = '?count=20';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$data =  $twitter->setGetfield($getfield)
             ->buildOauth($url, $requestMethod)
            ->performRequest();
$data = json_decode($data);
foreach($data as $v){
        echo $v->text.'<br>';
}
?>

 

 

 

3. 트위터 연동을위한 Class
TwitterAPIExchange.php

<?php

/**
* Twitter-API-PHP : Simple PHP wrapper for the v1.1 API
*
* PHP version 5.3.10
*
* @category Awesomeness
* @package Twitter-API-PHP
* @author James Mallison <me@j7mbo.co.uk>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @link http://github.com/j7mbo/twitter-api-php
*/
class TwitterAPIExchange
{
    private $oauth_access_token;
    private $oauth_access_token_secret;
    private $consumer_key;
    private $consumer_secret;
    private $postfields;
    private $getfield;
    protected $oauth;
    public $url;

    /**
* Create the API access object. Requires an array of settings::
* oauth access token, oauth access token secret, consumer key, consumer secret
* These are all available by creating your own application on dev.twitter.com
* Requires the cURL library
*
* @param array $settings
*/
    public function __construct(array $settings)
    {
        if (!in_array('curl', get_loaded_extensions()))
        {
            throw new Exception('You need to install cURL, see: http://curl.haxx.se/docs/install.html');
        }
        
        if (!isset($settings['oauth_access_token'])
            || !isset($settings['oauth_access_token_secret'])
            || !isset($settings['consumer_key'])
            || !isset($settings['consumer_secret']))
        {
            throw new Exception('Make sure you are passing in the correct parameters');
        }

        $this->oauth_access_token = $settings['oauth_access_token'];
        $this->oauth_access_token_secret = $settings['oauth_access_token_secret'];
        $this->consumer_key = $settings['consumer_key'];
        $this->consumer_secret = $settings['consumer_secret'];
    }
    
    /**
* Set postfields array, example: array('screen_name' => 'J7mbo')
*
* @param array $array Array of parameters to send to API
*
* @return TwitterAPIExchange Instance of self for method chaining
*/
    public function setPostfields(array $array)
    {
        if (!is_null($this->getGetfield()))
        {
            throw new Exception('You can only choose get OR post fields.');
        }
        
        if (isset($array['status']) && substr($array['status'], 0, 1) === '@')
        {
            $array['status'] = sprintf("\0%s", $array['status']);
        }
        
        $this->postfields = $array;
        
        return $this;
    }
    
    /**
* Set getfield string, example: '?screen_name=J7mbo'
*
* @param string $string Get key and value pairs as string
*
* @return \TwitterAPIExchange Instance of self for method chaining
*/
    public function setGetfield($string)
    {
        if (!is_null($this->getPostfields()))
        {
            throw new Exception('You can only choose get OR post fields.');
        }
        
        $search = array('#', ',', '+', ':');
        $replace = array('%23', '%2C', '%2B', '%3A');
        $string = str_replace($search, $replace, $string);
        
        $this->getfield = $string;
        
        return $this;
    }
    
    /**
* Get getfield string (simple getter)
*
* @return string $this->getfields
*/
    public function getGetfield()
    {
        return $this->getfield;
    }
    
    /**
* Get postfields array (simple getter)
*
* @return array $this->postfields
*/
    public function getPostfields()
    {
        return $this->postfields;
    }
    
    /**
* Build the Oauth object using params set in construct and additionals
* passed to this method. For v1.1, see: https://dev.twitter.com/docs/api/1.1
*
* @param string $url The API url to use. Example: https://api.twitter.com/1.1/search/tweets.json
* @param string $requestMethod Either POST or GET
* @return \TwitterAPIExchange Instance of self for method chaining
*/
    public function buildOauth($url, $requestMethod)
    {
        if (!in_array(strtolower($requestMethod), array('post', 'get')))
        {
            throw new Exception('Request method must be either POST or GET');
        }
        
        $consumer_key = $this->consumer_key;
        $consumer_secret = $this->consumer_secret;
        $oauth_access_token = $this->oauth_access_token;
        $oauth_access_token_secret = $this->oauth_access_token_secret;
        
        $oauth = array(
            'oauth_consumer_key' => $consumer_key,
            'oauth_nonce' => time(),
            'oauth_signature_method' => 'HMAC-SHA1',
            'oauth_token' => $oauth_access_token,
            'oauth_timestamp' => time(),
            'oauth_version' => '1.0'
        );
        
        $getfield = $this->getGetfield();
        
        if (!is_null($getfield))
        {
            $getfields = str_replace('?', '', explode('&', $getfield));
            foreach ($getfields as $g)
            {
                $split = explode('=', $g);
                $oauth[$split[0]] = $split[1];
            }
        }
        
        $base_info = $this->buildBaseString($url, $requestMethod, $oauth);
        $composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
        $oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
        $oauth['oauth_signature'] = $oauth_signature;
        
        $this->url = $url;
        $this->oauth = $oauth;
        
        return $this;
    }
    
    /**
* Perform the acual data retrieval from the API
*
* @param boolean $return If true, returns data.
*
* @return json If $return param is true, returns json data.
*/
    public function performRequest($return = true)
    {
        if (!is_bool($return))
        {
            throw new Exception('performRequest parameter must be true or false');
        }
        
        $header = array($this->buildAuthorizationHeader($this->oauth), 'Expect:');
        
        $getfield = $this->getGetfield();
        $postfields = $this->getPostfields();

        $options = array(
            CURLOPT_HTTPHEADER => $header,
            CURLOPT_HEADER => false,
            CURLOPT_URL => $this->url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_SSL_VERIFYPEER => false
        );

        if (!is_null($postfields))
        {
            $options[CURLOPT_POSTFIELDS] = $postfields;
        }
        else
        {
            if ($getfield !== '')
            {
                $options[CURLOPT_URL] .= $getfield;
            }
        }

        $feed = curl_init();
        curl_setopt_array($feed, $options);
        $json = curl_exec($feed);
        curl_close($feed);

        if ($return) { return $json; }
    }
    
    /**
* Private method to generate the base string used by cURL
*
* @param string $baseURI
* @param string $method
* @param string $params
*
* @return string Built base string
*/
    private function buildBaseString($baseURI, $method, $params)
    {
        $return = array();
        ksort($params);
        
        foreach($params as $key=>$value)
        {
            $return[] = "$key=" . $value;
        }
        
        return $method . "&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $return));
    }
    
    /**
* Private method to generate authorization header used by cURL
*
* @param array $oauth Array of oauth data generated by buildOauth()
*
* @return string $return Header used by cURL for request
*/
    private function buildAuthorizationHeader($oauth)
    {
        $return = 'Authorization: OAuth ';
        $values = array();
        
        foreach($oauth as $key => $value)
        {
            $values[] = "$key=\"" . rawurlencode($value) . "\"";
        }
        
        $return .= implode(', ', $values);
        return $return;
    }

}

?> 

Posted by requireme
Linux2013. 6. 7. 16:20


SSL 인증서 키에 비밀번호가 걸려있을때 비밀번호를 제거하는 방법.

 

~]# openssl rsa -in ssl.key -out ssl_nopass.key

     Enter pass phrase for ssl.key: 비밀번호 입력

 


반대로 비밀번호 없는 인증서 키에 비밀번호 거는방법

~]# openssl rsa -in ssl_nopass.key -passout pass:'password123' -out ssl.key -des3



 

끝.

 

 

'Linux' 카테고리의 다른 글

NSF 설치 및 설정  (0) 2015.06.24
apache에서 mp4 스트리밍하기  (0) 2014.03.07
PHP5 설치  (0) 2010.10.28
아파치 설치  (0) 2010.10.28
[Mysql] characterset이 euckr인 mysql 서버에서 utf8 Database 생성하기  (0) 2010.10.28
Posted by requireme
기타 개발관련2010. 12. 20. 14:54



1. bit.ly 사이트에 가입하여 api key를 발급받는다.

2. 몇가지 기능들이 있지만 나에게는 shorten 이외의 기능은 쓸일이 거의 없을듯..

3. 파라미터 값을 던져주고 변환된 짧은 주소를 받는다.

끝.


[파라미터]
login       : bit.ly 에 가입한 계정 ID
apiKey    : bit.ly 에서 발급받은 api key
longUrl    : 변경할 긴 주소 URL
format     : 리턴값의 format  (txt, xml, json)
domain   : 리턴값 도메인 (bit.ly 또는 j.mp 등 선택 가능)



[예제]

<html>
<body>
<form action="http://api.bit.ly/v3/shorten" method="get">
<input type="text" name="login" value="bit.ly 아이디" />
<input type="text" name="apiKey" value="발급받은 key />
<input type="text" name="longUrl" value="긴 URL 주소" />
<input type="text" name="format" value="txt" />
<input type="text" name="domain" value="j.mp" />
<input type="submit" />
</form>
</body>
</html>

Posted by requireme
Linux2010. 10. 28. 18:21


yum install libmcrypt \
libmcrypt-devel




#cd /usr/local/src/apm
tar zxvf php-5.3.3.tar.gz
cd php-5.5.5
./configure \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql=/usr/local/mysql \
--disable-debug \
--disable-posix \
--disable-rpath \
--disable-dmalloc \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir  \
--with-zlib \
--with-iconv \
--with-xmlrpc \
--with-config-file-path=/usr/local/apache2/conf \
--with-mcrypt \
--with-curl \
--with-mhash \
--with-openssl \
--with-mcrypt \
--with-kerberos \
--with-gmp \
--enable-bcmath \
--enable-mbstring \
--enable-ftp \
--enable-sockets \
--enable-calendar \
--enable-safe-mode \
--enable-magic-quotes \
--enable-gd-native-ttf \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx

# make
# make install
# cp php.ini-production /usr/local/apache/conf/php.ini

# vi /usr/local/apache/conf/httpd.conf
// ServerName 변경
ServerName localhost:80

// DirectoryIndex 에 추가 
DirectoryIndex index.html index.htm index.php

// AddType 추가
AddType application/x-httpd-php .php .phtml .php3 .html .htm 
AddType application/x-httpd-php-source .phps 

// 권한 변경
<Directory />
Optionis FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all 을 Allow from all 으로 변경
</Directory>




# vi /usr/local/apache/conf/mime.types
// 끝에 mime type 추가
application/x-httpd-php  php ph inc
application/x-httpd-php-source phps





Posted by requireme
Linux2010. 10. 28. 17:42



mkdir /usr/local/apache2
cd /usr/local/src/apm
tar zxvf httpd-2.2.13.tar.gz
cd httpd-2.2.13

./configure \
--prefix=/usr/local/apache2 \
--enable-module=so \
--enable-so \
--enable-mods-shared=all \
--enable-rewrite \
--enable-ssl 
make
make install 

Posted by requireme
Linux2010. 10. 28. 15:17



1. 서버에 utf8 Database 생성하기
mysql>create database db_name  default character set utf8   default collate utf8_general_ci ;


2. Mysql Client 의 utf8 연결
mysql>set names utf8;



3. 서버에 euckr Database 생성하기
mysql>create database db_name  default character set euckr  default collate euckr_korean_ci ;



'Linux' 카테고리의 다른 글

SSL 인증서 비밀번호 제거하는 방법  (0) 2013.06.07
PHP5 설치  (0) 2010.10.28
아파치 설치  (0) 2010.10.28
CentOS5에 mysql5 설치  (0) 2010.10.28
webalizer 설치 및 사용법  (0) 2010.08.04
Posted by requireme
Linux2010. 10. 28. 15:07


CentOS 5.5 버전에 mysql 5.1.51 설치.


1. 다운로드 
http://www.mysql.com/downloads/mysql/#downloads  에서 mysql-5.1.51.tar.gz  파일을 다운로드 받는다.






2. 설치

* 사용자 홈디렉토리 없이 mysql 계정 생성
#useradd mysql -M -s /bin/false

* mysql을 설치할 디렉토리 생성
#mkdir /usr/local/mysql

* 압축을  풀고 설치 디렉토리로 이동
#cd /usr/local/src/apm
#tar zxvf mysql-5.1.51.tar.gz 
#cd mysql-5.1.51

* 컴파일 옵션
#./configure \
--prefix=/usr/local/mysql \
--with-charset=euckr \
--with-extra-charsets=all \
--disable-shared \
--enable-assembler \
--with-mysqld-user="mysql" \
--with-client-ldflags=-all-static \
--with-mysqld-ldflags=-all-static \
--with-readline \
--without-debug \
--without-docs

--prefix=/usr/local/mysql               : install architecture-independent files in PREFIX
--with-charset=euckr                      :  Default character set
--with-extra-charsets=all                :  Use charsets in addition to default 
--disable-shared                           : --enable-shared[=PKGS]  build shared libraries [default=yes]
--enable-assembler                       :  Use assembler versions of some string
--with-mysqld-user="mysql"           :  What user the mysqld daemon shall be run as.
--with-client-ldflags=-all-static        :  Extra linking arguments for client
--with-mysqld-ldflags=-all-static     :  Extra linking arguments for mysqld
--with-readline                              :  Use system readline instead of bundled copy.
--without-debug                            : Add debug code
--without-docs                              :  Skip building of the documentation.


* 컴파일
#make & make install

* mysql 설정파일 복사
#cp /usr/local/mysql/share/mysql/my-huge.cnf /etc/my.cnf 

* 시스템 메모리 크기에따른 설정파일
my-huge.cnf       1G 이상
my-large.cnf       512M ~ 1G
my-medium.cnf  128M ~ 256M
my-small.cnf      64M 이하


* 기본 DB 생성
#/usr/local/mysql/bin/mysql_install_db

* mysql data 디렉토리 권한 변경
#chown -Rf mysql:mysql /usr/local/mysql/var

* mysql 데몬 실행하기
#/usr/local/mysql/bin/mysqld_safe &


* /etc/rc.d/rc.local 파일에 데몬 실행 스크립트를 추가하여 서버 부팅시 자동으로 실행되도록 한다.
#vi /etc/rc.d/rc.local
/usr/local/mysql/bin/mysqld_safe &



* PATH를 설정하여 어디서든 mysql 관련 명령어를 실행할수 있도록 한다.
#vi ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin




'Linux' 카테고리의 다른 글

SSL 인증서 비밀번호 제거하는 방법  (0) 2013.06.07
PHP5 설치  (0) 2010.10.28
아파치 설치  (0) 2010.10.28
[Mysql] characterset이 euckr인 mysql 서버에서 utf8 Database 생성하기  (0) 2010.10.28
webalizer 설치 및 사용법  (0) 2010.08.04
Posted by requireme
Linux2010. 8. 4. 11:42



아파치 웹로그 분석 툴인 webalizer 의 설치 및 사용 방법.


1. 설치하기.

cd /usr/local/src/
wget  ftp://ftp.mrunix.net/pub/webalizer/webalizer-2.21-02-src.tgz
tar zxvf webalizer-2.21-02-src.tgz
cd webalizer-2.21-02
./configure --prefix=/etc/webalizer --with-language=korean --with-pnglib=/usr/local/libpng/lib --with-gdlib=/usr/local/libgd/lib --with-gd=/usr/local/libgd/include
make
make install
cp sample.conf /etc/webalizer.conf

2. 사용하기.

/etc/webalizer.conf 파일 수정
--------------------------------------------------------
LogFile        /home/logs/access_log
OutputDir      /home/WEBSITE/myDIR/webalizer
HistoryName     www.domainn.com
HostName        www.domain.com
--------------------------------------------------------


* 웹페이지 생성
/etc/webalizer/bin/webalizer  -c /etc/webalizer.conf

* 확인
OutputDir의 웹경로로 확인.

* 여러 사이트에 적용하기 위해서는 /etc/webalizer.conf 파일을 다른이름으로 여러개 생성하여 파일별로 설정을 변경한다.
/etc/webalizer/bin/webalizer  -c /etc/webalizer.conf
/etc/webalizer/bin/webalizer  -c /etc/webalizer02.conf
/etc/webalizer/bin/webalizer  -c /etc/webalizer03.conf

'Linux' 카테고리의 다른 글

SSL 인증서 비밀번호 제거하는 방법  (0) 2013.06.07
PHP5 설치  (0) 2010.10.28
아파치 설치  (0) 2010.10.28
[Mysql] characterset이 euckr인 mysql 서버에서 utf8 Database 생성하기  (0) 2010.10.28
CentOS5에 mysql5 설치  (0) 2010.10.28
Posted by requireme
기타 개발관련2010. 7. 28. 15:57



이클립스를 설치하고나면

실행시마다 workspace 폴더 설정메시지를 만나게 된다.

매번 닫기가 귀찮으므로 다음부터 이 메시지가 뜨지 않도록 체크를 하면, 이후에는 workspace를 변경 할 방법이 없다.

하지만 설정파일을 수정함으로써 workspace를 재설정 할 수 있다.



%이클립스폴더%\configuration\.settings\org.eclipse.ui.ide.prefs 파일을 열어서

RECENT_WORKSPACES 값을 변경한다.


* 주의 : \ 의 표기에 주의 할 것.

Posted by requireme