나는 twitter api에 매우 익숙하다. 오늘은 내 인생에서 twitter api에 처음 가입했다. 내 목표는 내 웹 사이트의 사진을 트위터에 게시하는 것입니다. 인터넷에서 현재 라이브러리를 다운로드 받았으며, 다음과 같은 두 개의 파일과 예제를 제공합니다. 내가이Oauth, API, JSON 및 PHP를 사용하여 트위터에 그림을 업로드하는 방법
이 두 파일을 포함하고이 코드 photo_tweet.php 여기 내 코드
<?php
require 'tmhOAuth.php';
require 'tmhUtilities.php';
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => 'ZlhOWeCWG2MS5Wxxxxxx',
'consumer_secret' => 'DIPjoKcIWjpGWmw5jGJSKGAOLxxxxxx',
'user_token' => 'xxxxx-OGtPyRSUOUaR6XQRLAFVuv14xxxxxx',
'user_secret' => 'xxxxxoimsrNFhlz7mPa9h5pyVSjxxxxxxx',
));
// we're using a hardcoded image path here. You can easily replace this with
// an uploaded image - see images.php in the examples folder for how to do this
// 'image = "@{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}",
// this is the jpeg file to upload. It should be in the same directory as this file.
$image = 'a.jpg';
$code = $tmhOAuth->request(
'POST',
'https://upload.twitter.com/1/statuses/update_with_media.json',
array(
'media[]' => "@{$image};type=image/jpeg;filename={$image}",
'status' => 'Picture time',
),
true, // use auth
true // multipart
);
if ($code == 200) {
tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
} else {
tmhUtilities::pr($tmhOAuth->response['response']);
}
?>
a.jpg 내 서버에있는 것입니다 사진
와 트윗을한다는 것을 의미한다.
여기 내 트위터 설정입니다!
요청 유형 : GET 요청 URI : * https://api.twitter.com/1/
나는이 모든 코드를 업로드하고 난 $ 코드를 에코 때, 빈 애추를 반환 내 코드에 액세스 할 때; 0을 반환합니다.
모든 것을 관찰하고 경험했습니다. 나는 너의 친절한 도움이 필요하다. 나는 당신에게 아주 고마워 할 것입니다.
Note : 이벤트 내 소비자 키와 소비자 비밀을 제거했을 때이 코드는 오류를 나타내지 않습니다. 그냥 빈 화면. 나는이 문제의 경우하지만 오류가 여기에
에 오류를 표시 할 경우에만 그것이 나
$consumerKey = $consumer_key;
$consumerSecret = $consumer_secret;
$OAuthToken = $user_token;
$OAuthSecret = $user_secret;
include "OAuth.php";
include "twitteroauth.php";
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $OAuthToken, $OAuthSecret);
$image = 'a.jpg';
$optsArray['status'] = 'Hi';
if (isset($_GET['msg'])) {
$tweetmsg = $_GET['msg'];
$tweet->post('statuses/update',$optsArray);
if($tweet)
echo "Your message has been sent to Twitter.";
else
echo "Your message has not been sent to Twitter.";
} else {
echo "Your message has not been sent to Twitter.";
}
을 위해 일하지만 난
을 사용하는 경우에만 상태를 게시 상태 코드입니다update_with_media.json
및
$ optsArray [ '미디어 [] @'] = "@ $ {} 이미지 ";
가 작동하지 않습니다이 문제를이 문서를 체크 아웃 할 수 있습니다
간단한 메시지를 게시하려면 Twitter를 사용해 보셨습니까? 먼저 코드/api 키/토큰을 테스트하는 간단한 메시지를 게시하는 것이 좋습니다 – Arfeen
테스트 할 다른 간단한 코드를 사용하지만 빈 화면도 제공합니다. 트위터 설정에서 내 키와 토큰을 올바르게 복사했습니다. –