Php/twitter/tmhOAuth
提供: 初心者エンジニアの簡易メモ
twhOAuthとは
画像付きtweetライブラリ
DL
git clone https://github.com/themattharris/tmhOAuth
サンプル
require_once __DIR__ . '/../../library/tmhOAuth/tmhOAuth.php';
$twConf = array(
'consumer_key' => $this->_consumer_key,
'consumer_secret' => $this->_consumer_secret,
'user_token' => $this->_oauth_token,
'user_secret' => $this->_oauth_token_secret,
// 'curl_ssl_verifypeer' => false
);
$tmhOAuth = new tmhOAuth($twConf);
$endpoint = $tmhOAuth->url('1.1/statuses/update_with_media');
$imageName = basename($imgpath);
$exp = "jpeg";
if (preg_match("/.(png|gif)$/", $imgpath, $matches)) {
$exp = $matches[1];
}
$image = file_get_contents($imgpath);
$params = array(
'media[]' => "{$image};type=image/{$exp};filename={$imageName}",
'status' => "{$msg}"
);
$code = $tmhOAuth->request('POST', $endpoint, $params, true, true);
if ($tmhOAuth->response["code"] == 200) {
return $tmhOAuth->response["response"];
} else {
return $tmhOAuth->response["error"];
}
参考
https://github.com/themattharris/tmhOAuthExamples/blob/master/web/photo_tweet.php
