2014-02-26 4 views
0

트위터에 상태 및 이미지를 게시하려고합니다. 상태는 트위터지만 이미지는 트위터가 아닙니다. 트윗에 대한트위터 상태지만 이미지가 아닙니다.

내 PHP 코드, 어떻게 미디어 포스트를 사용하여 이미지를 업로드하려면 지금

<?php 
session_start(); 
require_once('twitteroauth/twitteroauth.php'); 
require_once('config-sample.php'); 

if (isset($_REQUEST['oauth_token']) && $_SESSION['oauth_token'] !== $_REQUEST['oauth_token']) { 
    $_SESSION['oauth_status'] = 'oldtoken'; 
    header('Location: ./clearsessions.php'); 
} 

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']); 


$access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']); 

$_SESSION['access_token'] = $access_token; 

unset($_SESSION['oauth_token']); 
unset($_SESSION['oauth_token_secret']); 

if (200 == $connection->http_code) { 

    $_SESSION['status'] = 'verified'; 
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']); 

$content = $connection->get('account/verify_credentials'); 

$image='abc.jpg'; 

$image1=file_get_contents($image); 

$array_disp[0]=$image; 
$connection->post('statuses/update',array('status' =>'hello123', 'media[]'=>$image1)); 

$response=$connection->response['response']; 

} else { 

    header('Location: ./clearsessions.php'); 
} 

입니까?

답변

0

Abraham's 라이브러리를 사용하고있는 것 같습니다. upload_with_media에서는 작동하지 않습니다. 여기에 자신의 성명은이 library에서 twitteroauth 폴더를 다운로드하고 twitteroauth1 등의 프로젝트에 붙여되어이 문제

TwitterOAuth does not currently support media uploads. I hope to add support in the future

대체 방법에 있습니다. 이제 미디어로 트윗 할 때 require_once('twitteroauth1/twitteroauth.php');으로 전화하십시오.

(또는)

당신은 단순히 우리가 다운로드 한 twitteroauth 디렉토리를 복사하여 프로젝트에 교체 할 수 있습니다. 자, 코드가 require_once('twitteroauth/twitteroauth.php');이 될 것입니다. 이 일을해야합니다!

<?php 
session_start(); 
require_once('twitteroauth1/twitteroauth.php'); 
require_once('config-sample.php'); 
if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token'])  || empty($_SESSION['access_token']['oauth_token_secret'])) { 
header('Location: ./clearsessions.php'); 
} 

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,$_SESSION['access_token'] ['oauth_token'], $_SESSION['access_token']['oauth_token_secret']); 
$image='abc.jpg'; 
$content = $connection->get('account/verify_credentials'); 
$params = array('media[]' => "@{$image}", 'status' => "Testing upload"); 
$connection->post('statuses/update_with_media', $params,true); 
echo "Picture has uploades successfully"; 
?> 
관련 문제