特定キーワードに反応する自動RTBOTを作りたい。
突然の質問、失礼いたします。
私は特定のキーワードをRTするBOTを作ろうと1か月ほどネットで方法を調べているプログラミング初心者です。(ネットの質問の他、GOOGLE先生など一通り調べました)
現在twitteroath、OAth、retweet用PHPを未来サーバーにアップして作成を行おうとしているのですがエラーが出てしまいます。
改善点、誤りについて助言をいただけないでしょうか、よろしくお願いいたします。
〇retweet.php
<?php
require_once("twitteroauth.php");
$consumerKey = "";
$consumerSecret = "";
$accessToken = "";
$accessTokenSecret = "";
$twObj=new TwitterOAuth($consumerKey,$consumerSecret,$accessToken,$accessTokenSecret);
//Twitterで検索するワード
$search_word=urlencode('+); //#検索ワード1か検索ワード2 +でつなぐとand検索、+-でつなぐと検索除外
//API実行データ取得
//現時点で100ツイートまでしか取得不可
$vRequest=$twObj->OAuthRequest('https://api.twitter.com/1.1/search/tweets.json','GET',
array('q'=>$search_word,'count'=>'3','include_entities'=>'true'));//API 1.1で変更
//Jsonデータをオブジェクトに変更
$oObj=json_decode($vRequest);
//オブジェクトを展開
$oObj=$oObj->{'statuses'};//API 1.1でresultsからstatusesに変更
for($i_tweet=0; $i_tweet < sizeof($oObj); $i_tweet++){ $id_str=(string)$oObj[$i_tweet]->{'id_str'};//つぶやきのID
echo $twObj->OAuthRequest( 'https://api.twitter.com/1.1/statuses/retweet/'$id_str.'.json','POST','');
?>
〇Oath
$timestamp
);
if ($found) {
throw new OAuthException("Nonce already used: $nonce");
}
}
}
class OAuthDataStore {
function lookup_consumer($consumer_key) {
// implement me
}
function lookup_token($consumer, $token_type, $token) {
// implement me
}
function lookup_nonce($consumer, $token, $nonce, $timestamp) {
// implement me
}
function new_request_token($consumer, $callback = null) {
// return a new token attached to this consumer
}
function new_access_token($token, $consumer, $verifier = null) {
// return a new access token attached to this consumer
// for the user associated with this token if the request token
// is authorized
// should also invalidate the request token
}
}
class OAuthUtil {
public static function urlencode_rfc3986($input) {
if (is_array($input)) {
return array_map(array('OAuthUtil', 'urlencode_rfc3986'), $input);
} else if (is_scalar($input)) {
return str_replace(
'+',
' ',
str_replace('%7E', '~', rawurlencode($input))
);
} else {
return '';
}
}
// This decode function isn't taking into consideration the above
// modifications to the encoding process. However, this method doesn't
// seem to be used anywhere so leaving it as is.
public static function urldecode_rfc3986($string) {
return urldecode($string);
}
// Utility function for turning the Authorization: header into
// parameters, has to do some unescaping
// Can filter out any non-oauth parameters if needed (default behaviour)
public static function split_header($header, $only_allow_oauth_parameters = true) {
$pattern = '/(([-_a-z]*)=("([^"]*)"|([^,]*)),?)/';
$offset = 0;
$params = array();
while (preg_match($pattern, $header, $matches, PREG_OFFSET_CAPTURE, $offset) > 0) {
$match = $matches[0];
$header_name = $matches[2][0];
$header_content = (isset($matches[5])) ? $matches[5][0] : $matches[4][0];
if (preg_match('/^oauth_/', $header_name) || !$only_allow_oauth_parameters) {
$params[$header_name] = OAuthUtil::urldecode_rfc3986($header_content);
}
$offset = $match[1] + strlen($match[0]);
}
if (isset($params['realm'])) {
unset($params['realm']);
}
return $params;
}
// helper to try to sort out headers for people who aren't running apache
public static function get_headers() {
if (function_exists('apache_request_headers')) {
// we need this to get the actual Authorization: header
// because apache tends to tell us it doesn't exist
$headers = apache_request_headers();
// sanitize the output of apache_request_headers because
// we always want the keys to be Cased-Like-This and arh()
// returns the headers in the same case as they are in the
// request
$out = array();