当前位置: 首页>>代码示例>>PHP>>正文


PHP TwitterOAuth\TwitterOAuth类代码示例

本文整理汇总了PHP中Abraham\TwitterOAuth\TwitterOAuth的典型用法代码示例。如果您正苦于以下问题:PHP TwitterOAuth类的具体用法?PHP TwitterOAuth怎么用?PHP TwitterOAuth使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TwitterOAuth类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: PostImage

 function PostImage()
 {
     if (!isset($_POST['source']) || $_POST['source'] == "") {
         return "Missing required params";
     }
     $config = (include "/config.php");
     $source = $_POST['source'];
     $final = "";
     if (isset($_POST['message'])) {
         $orig = $_POST['message'];
         $final = FilterText($orig);
     }
     $access_token = $_SESSION['access_token'];
     $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
     $check = new TB_Twitter_Check();
     if (!$check->VerifyTweet($source, $final)) {
         return "Tweet is not valid";
         exit;
     }
     $media1 = $connection->upload('media/upload', array('media' => $source));
     $parameters = array('status' => $final, 'media_ids' => implode(',', array($media1->media_id_string)));
     $result = $connection->post('statuses/update', $parameters);
     if ($connection->getLastHttpCode() == 200) {
         return "success";
     } else {
         return "An unnknown error occured";
     }
 }
开发者ID:thinkingboxmedia,项目名称:ShareAPI,代码行数:28,代码来源:twitter_post.php

示例2: refresh

 public function refresh()
 {
     $oauth = new TwitterOAuth(\twitter\configuration::$consumerKey, \twitter\configuration::$consumerSecret);
     $accessToken = $oauth->oauth2('oauth2/token', ['grant_type' => 'client_credentials']);
     $this->twitter = new TwitterOAuth(\twitter\configuration::$consumerKey, \twitter\configuration::$consumerSecret, null, $accessToken->access_token);
     $this->update();
 }
开发者ID:GPierre-Antoine,项目名称:projetphp,代码行数:7,代码来源:Twitter.php

示例3: getTweets

function getTweets($notification)
{
    $twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
    $date = $notification['date'];
    $keywords = array("sirene", "gevaar", "ongeluk", "ambulance", "ziekenwagen", "ongeval", "gewond", "letsel", "brand", "vlam", "vuur", "brandweer", "blus", "water", "overval", "politie", "dief", "wapen", "letsel", "inbraak", "schiet", "misdrijf");
    $start_date = "since:" . date(DATE_FORMAT, $date);
    $end_date = "until:" . date(DATE_FORMAT, strtotime("+1 day", $date));
    //$search_string = $notification['town'] . " " . implode(" OR ", $keywords) . " -p2000 " . $start_date . " " . $end_date;
    $search_string = implode(" OR ", KEYWORDS_GEN) . " -p2000 -RT " . $start_date . " " . $end_date;
    $cur_min = min(100, $notification["num_tweets"]);
    $params = array('q' => $search_string, 'lang' => 'nl', 'count' => $cur_min);
    //$statuses = json_encode((array)$twitter->get("search/tweets", $params));
    $temp = (array) $twitter->get("search/tweets", $params);
    $statuses = $temp["statuses"];
    $total_num = count($statuses);
    $num_stat = count($statuses);
    $min_id = $statuses[$num_stat - 1]->id;
    while ($total_num < $notification["num_tweets"] && $num_stat >= $cur_min) {
        $cur_min = min($notification["num_tweets"] - $total_num, 100);
        $params = array('q' => $search_string, 'lang' => 'nl', 'count' => $cur_min, 'max_id' => $min_id);
        $new_temp = (array) $twitter->get("search/tweets", $params);
        $new_stat = $new_temp["statuses"];
        $num_stat = count($new_stat);
        $total_num = $total_num + $num_stat;
        $min_id = $new_stat[$num_stat - 1]->id;
        $statuses = array_merge($statuses, $new_stat);
    }
    //What do I do with the statuses?
    return json_encode($statuses);
}
开发者ID:Bram9205,项目名称:WebInfo,代码行数:30,代码来源:get_twitter.php

示例4: getLongLat

 public function getLongLat($query)
 {
     $GEOdatax = "";
     $GEOdata = "";
     if ($query != NULL) {
         $consumer = "3Hsr7qk9HEYseF9bpJA07Go6H";
         $consumersecret = "q1TjkWCHcPKrJn0YCmtKMwIHaXURI7ip3z5eDxDd4G0GxLsUOi";
         $accesstoken = "3803581341-FAlmx3CbE2amgcMyD2AkGYuLdRa7kZ3QcDSxj5a";
         $accesstokensecret = "1JtROKIjMaIhP6IJGMPGbTyRTF9WMyq1RGclpdvcKzZWD";
         $twitter = new TwitterOAuth($consumer, $consumersecret, $accesstoken, $accesstokensecret);
         $url = "geo/search";
         $GEOquery = $twitter->get($url, array('query' => $query, 'granularity' => 'city', 'max_results' => '1'));
         foreach ($GEOquery->result->places as $GEOresult) {
             $GEOdata = $GEOresult->centroid;
             $GEOtype = $GEOresult->place_type;
         }
         if ($GEOdata != NULL) {
             $GEOdatax = implode(',', $GEOdata);
             if ($GEOtype == "country") {
                 $radius = ',479km';
             } else {
                 $radius = ',35mi';
             }
             $GEOdatax = $GEOdatax . $radius;
         }
     }
     return $GEOdatax;
 }
开发者ID:haythameyd,项目名称:socialfp,代码行数:28,代码来源:searchController.php

示例5: perform_request

/**
 * Performs a request using the TwitterOAuth library
 * @see https://twitteroauth.com/
 * @param $action - what to retrieve from the Twitter REST API (e.g. trends/place )
 * @param $params - parameters to be passed during the Twitter API request
 */
function perform_request($action, $params){

  $connection = new TwitterOAuth(TwitterConfig::$consumerKey, TwitterConfig::$consumerSecret, TwitterConfig::$accessToken, TwitterConfig::$accessTokenSecret);
  $response = $connection->get($action, $params);

  echo json_encode($response);
}
开发者ID:rwachtler,项目名称:twitstats,代码行数:13,代码来源:twitter-handler.php

示例6: getPosts

 public function getPosts()
 {
     //接続情報
     $connection = new TwitterOAuth($this->consumerKey, $this->consumerSecret, $this->accessToken, $this->accessTokenSecret);
     $content = $connection->get("search/tweets", ["geocode" => $this->location, "result_type" => "recent"]);
     return $content;
 }
开发者ID:RyosukeMurai,项目名称:TokyoSearch,代码行数:7,代码来源:Twitter.php

示例7: actionTweets

 public function actionTweets()
 {
     $postData = Yii::$app->getRequest()->getBodyParams();
     if (isset($postData['latitude']) && $postData['latitude'] && isset($postData['longitude']) && $postData['longitude']) {
         $data = Yii::$app->cache->get($postData['city']);
         if ($data === false) {
             // $data is expired or is not found in the cache
             $geocode = $postData['latitude'] . ',' . $postData['longitude'] . ',' . self::SEARCH_RADIUS;
             $connection = new TwitterOAuth('wT8o4IrBGCCNcnHxZfobEvHVV', 'eG3GQ7nqMXzO14IK7whGd1SyQmWqrKKRfgJJXmeqp910ryA3NV', '2376724225-0m1tu3Q8ru20mTyA0zjxGFKxRBEQkBTaTCAszQl', 'FEuuyd15giBingpwBgpIlQ0T419cUKcAA4kPJF6QLmiNb');
             $tweets = $connection->get("search/tweets", array("geocode" => $geocode));
             $result = [];
             foreach ($tweets->statuses as $tweet) {
                 //check tweet with geo exist
                 if (isset($tweet->geo) && is_array($tweet->geo->coordinates) && count($tweet->geo->coordinates) > 0) {
                     $result[] = array('desc' => $tweet->text, 'avatar' => $tweet->user->profile_image_url, 'created_at' => $tweet->created_at, 'lat' => $tweet->geo->coordinates[0], 'long' => $tweet->geo->coordinates[1]);
                 }
             }
             $this->insertTweets($postData['city'], $result);
             Yii::$app->cache->set($postData['city'], $result, self::CACHE_TIME);
             return ['success' => true, 'result' => $result];
         } else {
             return ['success' => true, 'result' => $data];
         }
     }
     return ['success' => false, 'result' => []];
 }
开发者ID:duykhoa87,项目名称:searchTweets,代码行数:26,代码来源:ApiController.php

示例8: _callbackFlow

 private function _callbackFlow()
 {
     // 不正認証防止用に認証リクエスト用トークンをチェック
     if ($_GET['oauth_token'] !== $_SESSION['tmp_twitter_oauth_token']) {
         echo "Invalid Token!";
         exit;
     }
     // twitterのユーザー情報の取得
     $conn = new TwitterOAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, $_SESSION['tmp_twitter_oauth_token'], $_SESSION['tmp_twitter_oauth_token_secret']);
     $tokens = $conn->oauth('oauth/access_token', ['oauth_verifier' => $_GET['oauth_verifier']]);
     //取得したtwitterユーザー情報をDBに登録もしくは更新
     $user = new \App\Model\User();
     if ($user->existsTwitterUser($tokens['user_id'])) {
         if (!$user->updateTwitterUser($tokens)) {
             echo "update error!";
             exit;
         }
     } else {
         if (!$user->createTwitterUser($tokens)) {
             echo "create error!";
             exit;
         }
     }
     //ログイン処理
     session_regenerate_id(true);
     $_SESSION['user'] = $user->findTwitterUser(['tw_user_id' => $tokens['user_id']]);
     //認証リクエスト用トークンはもう使わないので消す
     unset($_SESSION['tmp_twitter_oauth_token']);
     unset($_SESSION['tmp_twitter_oauth_token_secret']);
     header('Location: ' . SITE_URL);
     exit;
 }
开发者ID:a-tagai,项目名称:login_app,代码行数:32,代码来源:AuthTwitter.php

示例9: GetFollowersIds

	function GetFollowersIds()
	{
		/*session_start();
		$connection = new TwitterOAuth("CONSUMER_KEY",
			"CONSUMER_SECRET");
		$_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
		$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
		$url = $connection->getAuthorizeURL($token);

		$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']);

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

		$content = $connection->get('followers/ids');
		var_dump($content);*/

		$connection = new TwitterOAuth("CONSUMER_KEY",
			"CONSUMER_SECRET");
		$access_token = $connection->oauth("oauth/access_token",
			array("oauth_verifier" => 'CONSUMER_KEY'));
		var_dump($access_token);
	}
开发者ID:ballanar666,项目名称:tvp-lab8,代码行数:33,代码来源:twiapi.php

示例10: setLogin

 public static function setLogin($token, $isadmin = false, $db)
 {
     $_auth['tw_token'] = $token;
     $twitter = new TwitterOAuth(tw_consumer_key, tw_consumer_secret, $token['oauth_token'], $token['oauth_token_secret']);
     $response = $twitter->get('account/verify_credentials');
     $user = array('id' => $response->id, 'name' => $response->name, 'screen_name' => $response->screen_name, 'location' => $response->location, 'time_zone' => $response->time_zone, 'verified' => $response->verified, 'profile_image_url' => $response->profile_image_url, 'lang' => $response->lang);
     $_auth['user'] = $user;
     $_auth['isadmin'] = $user['id'] === 83455478;
     // $_auth['twitter']=$twitter;
     $sth = $db->prepare('INSERT INTO login
   (
     twitter_id,
     twitter_name,
     twitter_screen_name,
     twitter_location,
     twitter_time_zone,
     twitter_lang
   )
     VALUES
     (
       :twitter_id,
       :twitter_name,
       :twitter_screen_name,
       :twitter_location,
       :twitter_time_zone,
       :twitter_lang
     )');
     $sth->execute(array(':twitter_id' => $user['id'], ':twitter_name' => $user['name'], ':twitter_screen_name' => $user['screen_name'], ':twitter_location' => $user['location'], ':twitter_time_zone' => $user['time_zone'], ':twitter_lang' => $user['lang']));
     $_auth['login_id'] = $db->lastInsertId();
     session::set('auth', $_auth);
 }
开发者ID:emreplt,项目名称:keepitter,代码行数:31,代码来源:auth.php

示例11: execute

 /**
  * @return void
  * @throws \Exception
  */
 public function execute()
 {
     $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
     $data = $this->getRequest()->getParams();
     /* Get temporary credentials from session. */
     $request_token = [];
     $request_token['oauth_token'] = $this->scopeConfig->getValue('sama_twitterfeed/oauth/token', $storeScope);
     $request_token['oauth_token_secret'] = $this->scopeConfig->getValue('sama_twitterfeed/oauth/token_secret', $storeScope);
     /* If denied, bail. */
     if (isset($data['denied'])) {
         throw new Exception("Twitter denied permission");
     }
     /* If the oauth_token is not what we expect, bail. */
     if (isset($data['oauth_token']) && $request_token['oauth_token'] !== $data['oauth_token']) {
         throw new Exception("Unexpected Oauth token");
     }
     /* Create TwitteroAuth object with app key/secret and token key/secret from default phase */
     $connection = new TwitterOAuth($this->_oAuthkey, $this->_oAuthsecret, $request_token['oauth_token'], $request_token['oauth_token_secret']);
     /* Request access tokens from twitter */
     $access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $data['oauth_verifier']));
     /* If HTTP response is 200 continue otherwise send to connect page to retry */
     if (200 == $connection->getLastHttpCode()) {
         $this->_objectManager->get('Magento\\Framework\\App\\MutableScopeConfig')->setValue('sama_twitterfeed/oauth/access_token', $access_token);
         $this->_objectManager->get('Magento\\Framework\\App\\MutableScopeConfig')->setValue('sama_twitterfeed/oauth/token_secret', null);
         $this->_objectManager->get('Magento\\Framework\\App\\MutableScopeConfig')->setValue('sama_twitterfeed/oauth/token', null);
     } else {
         throw new Exception("Twitter Oauth API status code: {$connection->getLastHttpCode()}");
     }
     return;
 }
开发者ID:sandermangel,项目名称:magento2-twitterfeed,代码行数:34,代码来源:Callback.php

示例12: Oauth

 public function Oauth()
 {
     $oauth = new TwitterOAuth($this->key, $this->secret);
     $accessToken = $oauth->oauth2('oauth2/token', ['grant_type' => 'client_credentials']);
     $twitter = new TwitterOAuth($this->key, $this->secret, null, $accessToken->access_token);
     return $twitter;
 }
开发者ID:wilrona,项目名称:ApplicationDT,代码行数:7,代码来源:TwitterComponent.php

示例13: setupTwitter

 /**
  * Setup TwitterOAuth
  *
  * $twitterAuthConf must contain
  * - consumer_key
  * - consumer_secret
  * - oauth_access_token
  * - oauth_access_token_secret
  *
  * @param array $twitterAuthConf
  * @return $this
  */
 public function setupTwitter(array $twitterAuthConf)
 {
     $twitterAuthConf += ['consumer_key' => null, 'consumer_secret' => null, 'oauth_access_token' => null, 'oauth_access_token_secret' => null];
     $this->twitter = new TwitterOAuth($twitterAuthConf['consumer_key'], $twitterAuthConf['consumer_secret'], $twitterAuthConf['oauth_access_token'], $twitterAuthConf['oauth_access_token_secret']);
     $this->twitter->setDecodeJsonAsArray(true);
     return $this;
 }
开发者ID:batopa,项目名称:chirp,代码行数:19,代码来源:Chirp.php

示例14: create

 public function create()
 {
     DB::transaction(function () {
         $twitterClient = new TwitterOAuth(Config::get('services.twitter.consumerKey'), Config::get('services.twitter.consumerSecret'), Config::get('services.twitter.accessToken'), Config::get('services.twitter.accessSecret'));
         // Fetch the tweet information from Twitter, if a tweet id was passed through (it is possible the tweet was created manually without an id)
         if (array_key_exists('tweet_id', $this->input)) {
             $tweet = $twitterClient->get('statuses/show', ['id' => $this->input['tweet_id']]);
             $tweetOwner = $tweet->user;
             $this->object = Object::create(['user_id' => Auth::id(), 'type' => MissionControlType::Tweet, 'tweet_text' => $tweet->text, 'tweet_id' => $tweet->id, 'tweet_parent_id' => $tweet->in_reply_to_status_id, 'size' => strlen($tweet->text), 'title' => $tweet->text, 'summary' => $this->input['summary'], 'cryptographic_hash' => hash('sha256', $tweet->text), 'originated_at' => Carbon::createFromFormat('D M d H:i:s P Y', $tweet->created_at)->toDateTimeString(), 'status' => ObjectPublicationStatus::QueuedStatus]);
         } else {
             $this->object = Object::create(['user_id' => Auth::id(), 'type' => MissionControlType::Tweet, 'tweet_text' => $this->input['tweet_text'], 'size' => strlen($this->input['tweet_text']), 'title' => $this->input['tweet_text'], 'summary' => $this->input['summary'], 'cryptographic_hash' => hash('sha256', $this->input['tweet_text']), 'originated_at' => $this->input['originated_at'], 'status' => ObjectPublicationStatus::QueuedStatus]);
         }
         try {
             if (!isset($tweetOwner)) {
                 $tweetOwner = $twitterClient->get('users/show', ['screen_name' => $this->input['tweet_screen_name']]);
             }
             $tweeter = Tweeter::byScreenName($tweetOwner->screen_name)->firstOrFail();
         } catch (ModelNotFoundException $e) {
             $tweeter = Tweeter::create(['screen_name' => $tweetOwner->screen_name, 'user_name' => $tweetOwner->name, 'description' => $tweetOwner->description]);
             $tweeter->saveProfilePicture();
         }
         $this->object->tweeter()->associate($tweeter);
         $this->createMissionRelation();
         $this->createTagRelations();
         $this->object->push();
     });
     return $this->object;
 }
开发者ID:RoryStolzenberg,项目名称:spacexstats,代码行数:28,代码来源:ObjectFromTweet.php

示例15: getAuthorizationUrl

 public function getAuthorizationUrl(array $options = [])
 {
     $connection = new TwitterOAuth($this->clientId, $this->clientSecret);
     $request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => $this->redirectUri));
     $options["session"]->write('twitter.request_token', $request_token);
     $url = $connection->url('oauth/authenticate', array('oauth_token' => $request_token['oauth_token']));
     return $url;
 }
开发者ID:kukiwasabi,项目名称:oauth2-twitter,代码行数:8,代码来源:Twitter.php


注:本文中的Abraham\TwitterOAuth\TwitterOAuth类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。