- PHP 트위터 API 사용
1 사전 작업[ | ]
2 twitter-api-php 설치[ | ]
Console
Copy
[root@zetawiki ~]# git clone https://github.com/J7mbo/twitter-api-php.git
Initialized empty Git repository in /root/twitter-api-php/.git/
remote: Counting objects: 120, done.
remote: Total 120 (delta 0), reused 0 (delta 0), pack-reused 120
Receiving objects: 100% (120/120), 19.90 KiB, done.
Resolving deltas: 100% (40/40), done.
3 post_hello_world.php 작성[ | ]
Console
Copy
[root@zetawiki ~]# cd twitter-api-php
[root@zetawiki twitter-api-php]# vi post_hello_world.php
PHP
Copy
<?php
require_once('TwitterAPIExchange.php');
$settings = array(
'consumer_key' => "컨슈머키",
'consumer_secret' => "컨슈머시크릿",
'oauth_access_token' => "액세스토큰",
'oauth_access_token_secret' => "액세스토큰시크릿"
);
$url = 'https://api.twitter.com/1.1/statuses/update.json';
$requestMethod = 'POST';
$postfields = array('status' => '안녕 친구들');
$twitter = new TwitterAPIExchange($settings);
echo $twitter->buildOauth($url, $requestMethod)
->setPostfields($postfields)
->performRequest();
- →
$settings
배열 내용은 자신의 정보에 맞게 수정
4 테스트[ | ]
Console
Copy
[root@zetawiki twitter-api-php]# php post_hello_world.php
{"created_at":"Sun Mar 01 14:33:41 +0000 2015","id":572042023663882240,
... (생략)
- 자신의 트위터 주소(
https://twitter.com/아이디
)로 접속하여 새 글 작성되었는지 확인
- (위 예시는 https://twitter.com/zetawiki/status/572042023663882240 으로 작성됨 )
5 같이 보기[ | ]
6 참고[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.