本文整理汇总了PHP中TwitterAPIExchange::buildOauth方法的典型用法代码示例。如果您正苦于以下问题:PHP TwitterAPIExchange::buildOauth方法的具体用法?PHP TwitterAPIExchange::buildOauth怎么用?PHP TwitterAPIExchange::buildOauth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TwitterAPIExchange
的用法示例。
在下文中一共展示了TwitterAPIExchange::buildOauth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
<?php
require 'API/TwitterAPIExchange.php';
$settings = array('oauth_access_token' => 'Your Access App Token', 'oauth_access_token_secret' => 'Your Access Secret App Token', 'consumer_key' => 'Your consumer_key', 'consumer_secret' => 'Tu Consumer_Secret');
$url = "https://api.twitter.com/1.1/statuses/update.json";
$requestMethod = 'POST';
//
$postfields = array('status' => 'Hola este es mi segundo Tweet, Gracias a todos #AprendanPHP');
// Crear la instancia de conexion con twitter
$twitter = new TwitterAPIExchange($settings);
$response = $twitter->buildOauth($url, $requestMethod)->setPostfields($postfields)->performRequest();
示例2: postTwitter
function postTwitter()
{
$url = 'https://upload.twitter.com/1.1/media/upload.json';
$requestMethod = 'POST';
$settings = array('consumer_key' => "yyDZQ8MvKof6NKHjh15jrFu8I", 'consumer_secret' => "aY2RJcTyM7HVyyUXMIedrGEW3OVVwE1F4f4gnSMB0yrjZJnKMg", 'oauth_access_token' => "711228384077074432-zQwT4Xlvy1cuxBM6rtyUxJdPafrtDQh", 'oauth_access_token_secret' => "ZgSXDRYwXAPlS81HuRvJlouh5zWJJMK4niFzeLzAa7YAL");
$postfields = array('media_data' => base64_encode(file_get_contents(getCaminhoImagem(getConnection()))));
try {
$twitter = new TwitterAPIExchange($settings);
echo "Enviando imagem...\n";
$retorno = $twitter->buildOauth($url, $requestMethod)->setPostfields($postfields)->performRequest(true);
echo $retorno . "\n";
$retorno = json_decode($retorno);
if (isset($retorno->error) && $retorno->error != "") {
return false;
}
$url = 'https://api.twitter.com/1.1/statuses/update.json';
$requestMethod = 'POST';
/** POST fields required by the URL above. See relevant docs as above **/
$postfields = array('status' => 'If you like SEXY GIRLS visit http://sluttyfeed.com/ - The best PORN on internet! - #porn #adult #hot #xxx', 'media_ids' => $retorno->media_id_string);
echo "\nPostando no twitter...\n";
$retorno = $twitter->buildOauth($url, $requestMethod)->setPostfields($postfields)->performRequest();
echo $retorno . "\n";
$retorno = json_decode($retorno);
if (isset($retorno->errors)) {
return false;
}
echo "Postado!\n";
return true;
} catch (Exception $ex) {
echo $ex->getMessage();
return false;
}
}
示例3: request
/**
* request method for accessing twitter endpoints
*
*
* @param string $url
* @param string $method
* @param array $fields
* @return string
* @throws Exception
*/
public function request($url, $method = 'POST', $fields = array())
{
if (!isset($url)) {
throw new Exception('SERVER: Unable to submit request to an empty URL.');
}
if ($method == 'GET') {
if (!empty($fields)) {
$queryStr = http_build_query($fields);
return $this->twitterAPIExchange->setGetfield($queryStr)->buildOauth($url, $method)->performRequest();
}
}
if ($method == 'POST') {
return $this->twitterAPIExchange->buildOauth($url, $method)->setPostfields($fields)->performRequest();
}
}
示例4: twitter_is_user_following
function twitter_is_user_following($twitterUser)
{
global $twitterAuth;
global $twitterApiUrls;
$twitter = new TwitterAPIExchange($twitterAuth);
$twitter->buildOauth($twitterApiUrls["get_followers_list"], "GET");
$followers = json_decode($twitter->performRequest());
$following = false;
//die (print_r($followers->users, true));
foreach ($followers->users as $follower) {
if ($follower->screen_name == $twitterUser) {
$following = true;
break;
}
}
return $following;
}
示例5: postRequest
private function postRequest($url, $params = array())
{
$postFields = array();
foreach ($params as $key => $value) {
$postFields[$key] = $value;
}
$twitter = new TwitterAPIExchange($this->creds['oauth']);
$response = $twitter->buildOauth($url, 'POST')->setPostfields($postFields)->performRequest();
return $response;
}
示例6: follow
function follow($usuario)
{
ini_set('display_errors', 1);
require_once 'plugins/twitter-api-exchange/TwitterAPIExchange.php';
$settings = array('oauth_access_token' => get_option("access_token"), 'oauth_access_token_secret' => get_option("access_token_secret"), 'consumer_key' => get_option("consumer_key"), 'consumer_secret' => get_option("consumer_secret"));
$url = 'https://api.twitter.com/1.1/friendships/create.json';
$requestMethod = 'POST';
$postfields = array('screen_name' => $usuario, 'follow' => "true");
$twitter = new TwitterAPIExchange($settings);
return $twitter->buildOauth($url, $requestMethod)->setPostfields($postfields)->performRequest();
}
示例7: uploadImg
/**
* Загрузка изображений
* $file - путь к загружаемому файлу
*/
public function uploadImg($file)
{
$file = file_get_contents(MODX_BASE_PATH . $file);
$data = base64_encode($file);
$url = 'https://upload.twitter.com/1.1/media/upload.json';
$requestMethod = 'POST';
$postfields = array('media_data' => $data);
$twitter = new TwitterAPIExchange($this->twKeys);
$request = $twitter->buildOauth($url, $requestMethod)->setPostfields($postfields)->performRequest();
$response = json_decode($request);
return $response;
}
示例8: log
/**
* @param string $level
* @param string $message
* @param array $context
*/
public function log($level, $message, array $context = [])
{
$message = '[' . strtoupper($level) . '] ' . $message;
// Set access tokens here - see: https://apps.twitter.com/
$settings = ['oauth_access_token' => $this->oAuthAccessToken, 'oauth_access_token_secret' => $this->oAuthAccessTokenSecret, 'consumer_key' => $this->consumerKey, 'consumer_secret' => $this->consumerKeySecret];
// URL for REST request, see: https://dev.twitter.com/rest/public
$url = 'https://api.twitter.com/1.1/direct_messages/new.json';
$requestMethod = 'POST';
// POST fields required by the URL above. See relevant docs as above
$postfields = ['screen_name' => $this->receiverScreenName, 'text' => $message];
// Perform the request and echo the response
$twitter = new \TwitterAPIExchange($settings);
$twitter->buildOauth($url, $requestMethod)->setPostfields($postfields)->performRequest(false);
}
示例9: twitter_pic2twitter
/**
* send @a message with @a picture to twitter.
* Supported image formats are PNG, JPG and GIF (Animated GIFs are not supported).
*/
function twitter_pic2twitter($message, $picture)
{
// Documentation see:
// https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media
$url = 'https://api.twitter.com/1.1/statuses/update_with_media.json ';
$requestMethod = 'POST';
// POST fields
$postfields = array('status' => $txt, 'media' => array(), 'lat' => '41.02', 'long' => '28.97', 'display_coordinates' => false);
// Perform a POST request and echo the response
$twitter = new TwitterAPIExchange($settings);
$result = $twitter->buildOauth($url, $requestMethod)->setPostfields($postfields)->performRequest();
if (get_debug()) {
echo $result;
}
}
示例10: actionSendtwitterblast
public function actionSendtwitterblast()
{
ini_set('display_errors', 1);
$message = $_POST['message'];
$settings = array('oauth_access_token' => "408895167-RW2Sd8IZddrzViscHqGHYysS414Hj92KqOPnEb4l", 'oauth_access_token_secret' => "10c2ZXjIOgAvcMAWgfp8qc87tbgrQIVorrQ7J6h5dTl7m", 'consumer_key' => "nvUS5zpy2CSYAwJ1vvtYbdmK6", 'consumer_secret' => "tZDsbHSFLCwGnt197ISN3OmK3fn1EdtQyYhMg9fpXU6P92sDJv");
$url = 'https://api.twitter.com/1.1/direct_messages/new.json';
$requestMethod = 'POST';
$connect = Yii::$app->db;
$account = $connect->createCommand("SELECT ACCOUNT FROM TEST_TWITTER WHERE ROWNUM <= 5")->queryAll();
foreach ($account as $rows) {
$akun = $rows['ACCOUNT'];
// array_push($postfields, array('screen_name' => $akun));
$postfields = array('text' => $message, 'screen_name' => 'Jutaan SME Telkom');
$twitter = new TwitterAPIExchange($settings);
echo $twitter->buildOauth($url, $requestMethod)->setPostfields($postfields)->performRequest();
}
}
示例11: send
/**
* @param Model_User $to
* @param Model_User $from
* @param string $message
* @return bool|string
*/
public function send($to, $from = "", $message = "")
{
if ($message == "") {
// Construct Tweet
$message = "@" . $to->getTwitterUsername() . " you were upvoted by @" . $from->getTwitterUsername() . " on magehero.com/" . $to->getGithubUsername();
}
$settings = array('oauth_access_token' => $this->_localConfig->get('twitter_oauth_access_token'), 'oauth_access_token_secret' => $this->_localConfig->get('twitter_oauth_access_token_secret'), 'consumer_key' => $this->_localConfig->get('twitter_consumer_api_key'), 'consumer_secret' => $this->_localConfig->get('twitter_consumer_api_secret'));
$url = 'https://api.twitter.com/1.1/statuses/update.json';
$requestMethod = 'POST';
$postfields = array("status" => $message);
try {
$twitter = new TwitterAPIExchange($settings);
$response = $twitter->buildOauth($url, $requestMethod)->setPostfields($postfields)->performRequest();
// Error handling for tweet failurs , is not required. I am pretty sure that the voters are not interested
// in knowing if the tweet was posted or now.
return $response;
} catch (Exception $e) {
return false;
}
//var_dump(json_decode($response));die;
}
示例12: tweet
function tweet()
{
global $APIsettings;
$categoryCodes = array('w', 'n', 'b', 'tc', 'e', 's');
$firstIdx = array_rand($categoryCodes);
$firstCat = $categoryCodes[$firstIdx];
unset($categoryCodes[$firstIdx]);
$categoryCodes = array_values($categoryCodes);
$topics = getTopics($firstCat);
if (count($topics) > 0) {
$firstTopic = $topics[array_rand($topics)];
$headline = getHeadline($firstTopic);
if ($headline != null && strstr($headline, $firstTopic->name) !== false) {
$secondCat = $categoryCodes[array_rand($categoryCodes)];
$newTopics = getTopics($secondCat);
if (count($newTopics) > 0) {
$secondTopic = $newTopics[array_rand($newTopics)];
$newHeadline = str_replace($firstTopic->name, $secondTopic->name, $headline);
if (strlen($newHeadline) < 141) {
// Post the tweet
$postfields = array('status' => $newHeadline);
$url = "https://api.twitter.com/1.1/statuses/update.json";
$requestMethod = "POST";
$twitter = new TwitterAPIExchange($APIsettings);
echo $twitter->buildOauth($url, $requestMethod)->setPostfields($postfields)->performRequest();
} else {
tweet();
}
} else {
tweet();
}
} else {
tweet();
}
} else {
tweet();
}
}
示例13: sendDirectMessage
function sendDirectMessage($param)
{
$url = $param['api_end_point'] . '/direct_messages/new.json';
$screen_name = $param['params']['screen_name'];
$text = $param['params']['message'];
$requestMethod = 'POST';
$postFields = array("screen_name" => $screen_name, 'text' => $text);
$twitter = new TwitterAPIExchange($param['settings']);
$response = $twitter->buildOauth($url, $requestMethod)->setPostfields($postFields)->performRequest();
return $response;
}
示例14: substr
if (strpos($te, '!') !== false && strpos($te, 'http') == false) {
$toTweetString .= str_replace("!", "?", $te) . ' ';
$exclaimCount++;
} else {
$toTweetString .= $te . ' ';
}
}
if ($exclaimCount > 0) {
$ripstring = str_replace("&", "&", $toTweetString);
$ripstring = substr($ripstring, 0, 140);
//$ripstring = rawurlencode($ripstring);
//if($client == 'cli') {
$twitterNew = new TwitterAPIExchange($settings);
$postfields = array('status' => $ripstring);
if (strpos($connectingip, 'the.only.allowed.ip') !== false) {
$postedTweet = $twitterNew->buildOauth('https://api.twitter.com/1.1/statuses/update.json', 'POST')->setPostfields($postfields)->performRequest();
} else {
}
file_put_contents('tweetattempts.html', date('m-d-Y h:iA') . '-' . $usuableTweets . '<br/>' . $postedTweet . '<br/>' . $connectingip . '<br/><br/>', FILE_APPEND | LOCK_EX);
array_unshift($oldArray, $tweet_id);
array_push($newIDs, $tweet_id);
//}
echo $toTweetString . '<br/><br/>';
$usuableTweets++;
}
} else {
}
}
//MAKE THE NEW FILE
$info = 'Last Update: ' . date('m-d-Y h:iA') . '<br/> From: ' . $client . '<br/> Number of Tweets: ' . $usuableTweets . '<br/> IP: ' . $_SERVER['REMOTE_ADDR'] . '<br/>Since: ' . $lastTweet . '<br/>Most Recent: ' . $most_recent;
file_put_contents('lastUpdate.html', $info);
示例15: discussionModel_afterSaveDiscussion_handler
/**
* Check requirements and publish new discussion to Twitter.
*
* @param object $sender DiscussionModel.
* @param array $args EventArguments.
* @return void.
* @package TwitterBot
* @since 0.1
*/
public function discussionModel_afterSaveDiscussion_handler($sender, $args)
{
$discussion = $args['Discussion'];
// Exit if this discussion has already been twittered.
if ($discussion->Attributes['TwitterBot'] == true) {
return;
}
// Exit if discussions from this category shouldn't be twittered
if (!in_array($discussion->CategoryID, Gdn::config('TwitterBot.CategoryIDs'))) {
return;
}
// Exit if the current user hasn't the permission to twitter
$roleIds = array_keys(Gdn::userModel()->getRoles($discussion->InsertUserID));
if (array_intersect($roles, Gdn::config('TwitterBot.RoleIDs'))) {
return;
}
// Exit if only announcements shall be twittered and this is no announcements
if (Gdn::config('TwitterBot.AnnouncementsOnly') && !$discussion->Announce) {
return;
}
// Exit if checkbox is shown and not ticked
if (Gdn::config('TwitterBot.ShowCheckbox') && !$args['FormPostValues']['TwitterBot']) {
return;
}
// Exit if plugin is not configured
$consumerKey = Gdn::config('TwitterBot.ConsumerKey');
$consumerSecret = Gdn::config('TwitterBot.ConsumerSecret');
$oAuthAccessToken = Gdn::config('TwitterBot.OAuthAccessToken');
$oAuthAccessTokenSecret = Gdn::config('TwitterBot.OAuthAccessTokenSecret');
if (!$consumerKey || !$consumerSecret || !$oAuthAccessToken || !$oAuthAccessTokenSecret) {
return;
}
$title = $discussion->Name;
$body = Gdn_Format::to($discussion->Body, $discussion->Format);
$author = $discussion->InsertName;
$date = $discussion->DateInserted;
$category = $discussion->Category;
$url = $discussion->Url;
$tweet = '"' . $title . '" by ' . $author;
require_once __DIR__ . '/library/vendors/twitter-api-php/TwitterAPIExchange.php';
$settings = array('oauth_access_token' => $oAuthAccessToken, 'oauth_access_token_secret' => $oAuthAccessTokenSecret, 'consumer_key' => $consumerKey, 'consumer_secret' => $consumerSecret);
$twitter = new TwitterAPIExchange($settings);
$response = $twitter->buildOauth('https://api.twitter.com/1.1/statuses/update.json', 'POST')->setPostfields(array('status' => $tweet))->performRequest();
$response = json_decode($response, true);
if (isset($response['created_at'])) {
// Gdn::controller()->informMessage('This discussion has been published on Twitter', 'Dismissable');
Gdn::discussionModel()->saveToSerializedColumn('Attributes', $discussion->DiscussionID, 'TwitterBot', true);
}
}