티스토리 뷰

728x90
반응형
php를 사용하신다면 twitter oauth 라이브러리중에 아주 유명한 abraham twitteroauth를 많이들 쓰고 계실것이라 생각합니다.


저도 twitter oauth 라이브러리를 가장 애용한답니다.

라이브러리를 사용하면서 다른 기능들은 무리없이 잘 사용하고 있는데

프로필 이미지 업데이트 기능에서 이미지를 첨부해야하는데

어떻게 사용해야하는건지 난감해 하고 있었는데

이미 twitteroauth.php에 추가 가능한 이미지 업로드 메소드를 이미 구현해 놓으신분들이 계시더군요.

일본에 계신분이었는데 구글링 덕분에 아주 쉽게 찾았습니다.


twitteroauth.php의 190줄 다음 http 함수가 나오기 전에 이 함수를 추가해주시고



function oAuthRequestImage($url, $method = NULL ,$args = array()) {
    $req = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, array());
    $req->sign_request($this->sha1_method, $this->consumer, $this->token);
    return $this->http($req->get_normalized_http_url(), $method,$args, $req->to_header());
}



http 함수에 다음 부분을 수정해주시면 됩니다.


function http($url, $method, $postfields = NULL,$header = '') { // header 파라메터 추가
  // 중략
  curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:',$header)); // array('Expect:')); 수정
  // 후략




그리고 아래와 같이 사용하시면 됩니다.


<?php
require_once("twitteroauth.php");

$consumer_key = "";
$consumer_secret = "";
$access_token = "";
$access_token_secret = "";

$to = new TwitterOAuth($consumer_key,$consumer_secret,$access_token,$access_token_secret);

// 아이콘 변경
$req = $to->OAuthRequestImage('https://twitter.com/account/update_profile_image.xml',"POST",array('image' => '@test.jpg'));
?>




직접 수정하시기 난감하신 분들을 위해 이 부분을 직접 수정한 최신 파일을 함께 업로드 합니다.

필요하신분 있으시면 유용하게 사용하셨으면 좋겠네요.



728x90
반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함