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


Scala ConfigurationBuilder类代码示例

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


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

示例1: OAuthUtils

//设置package包名称以及导入依赖的类
package org.iamShantanu101.spark.SentimentAnalyzer.utils

import twitter4j.auth.OAuthAuthorization
import twitter4j.conf.ConfigurationBuilder


object OAuthUtils {
  def bootstrapTwitterOAuth(): Some[OAuthAuthorization] = {
    System.setProperty("twitter4j.oauth.consumerKey", PropertiesLoader.consumerKey)
    System.setProperty("twitter4j.oauth.consumerSecret", PropertiesLoader.consumerSecret)
    System.setProperty("twitter4j.oauth.accessToken", PropertiesLoader.accessToken)
    System.setProperty("twitter4j.oauth.accessTokenSecret", PropertiesLoader.accessTokenSecret)

    val configurationBuilder = new ConfigurationBuilder()
    val oAuth = Some(new OAuthAuthorization(configurationBuilder.build()))

    oAuth
  }
} 
开发者ID:iamShantanu101,项目名称:Twitter-Sentiment-Analyzer-Apache-Spark-Mllib,代码行数:20,代码来源:OAuthUtils.scala

示例2: SparkSetup

//设置package包名称以及导入依赖的类
package com.databricks.apps

package twitterClassifier {
  import org.apache.spark.SparkContext
  import org.apache.spark.sql.SparkSession

  object SparkSetup {
    val spark = SparkSession
      .builder
      .appName(getClass.getSimpleName.replace("$", ""))
      .getOrCreate()

    val sqlContext = spark.sqlContext

    val sc: SparkContext = spark.sparkContext
    // Suppress "WARN BlockManager: Block input-0-1478266015800 replicated to only 0 peer(s) instead of 1 peers" messages
    sc.setLogLevel("ERROR")
  }
}

package object twitterClassifier {
  import org.apache.spark.mllib.linalg.Vector
  import org.apache.spark.mllib.feature.HashingTF
  import twitter4j.auth.OAuthAuthorization
  import twitter4j.conf.ConfigurationBuilder

  val numFeatures = 1000
  val tf = new HashingTF(numFeatures)

  def maybeTwitterAuth: Some[OAuthAuthorization] = Some(new OAuthAuthorization(new ConfigurationBuilder().build))

  
  def featurize(s: String): Vector = tf.transform(s.sliding(2).toSeq)
} 
开发者ID:krish121,项目名称:Spark-reference-applications,代码行数:35,代码来源:package.scala

示例3: TwitterClient

//设置package包名称以及导入依赖的类
package example.utils

import com.typesafe.config.ConfigFactory

import twitter4j._
import twitter4j.conf.ConfigurationBuilder
import twitter4j.json.DataObjectFactory

import TwitterClient._

case class TwitterClient {


  private val twitterStream = new TwitterStreamFactory(cb.build()).getInstance()

  def addListener(statusHandler: (Status => Unit)) = {
    val listener = new StatusListener() {
      def onStatus(status: Status) = statusHandler(status)
      def onDeletionNotice(statusDeletionNotice: StatusDeletionNotice) = {}
      def onTrackLimitationNotice(numberOfLimitedStatuses: Int) = {}
      def onScrubGeo(userId: Long, upToStatusId: Long) = {}
      def onException(ex: Exception) = {}
      def onStallWarning(warning: StallWarning) = {}
    }

    twitterStream.addListener(listener)
    listener
  }

  def run = twitterStream.sample();
}
object TwitterClient {
  val config = ConfigFactory.load()

  val consumerKey = config.getString("twitter.consumerKey")
  val consumerSecret = config.getString("twitter.consumerSecret")
  val accessToken = config.getString("twitter.accessToken")
  val accessTokenSecret = config.getString("twitter.accessTokenSecret")

  val cb = new ConfigurationBuilder()
  cb.setOAuthConsumerKey(consumerKey)
  cb.setOAuthConsumerSecret(consumerSecret)
  cb.setOAuthAccessToken(accessToken)
  cb.setOAuthAccessTokenSecret(accessTokenSecret)
  cb.setJSONStoreEnabled(true)
  cb.setIncludeEntitiesEnabled(true)

} 
开发者ID:alonsoir,项目名称:awesome-recommendation-engine,代码行数:49,代码来源:TwitterStream.scala

示例4: getSongs

//设置package包名称以及导入依赖的类
package services

import model.Song

import collection.JavaConversions._
import twitter4j._
import twitter4j.conf.ConfigurationBuilder

trait ITwitterService {
  def getSongs: Seq[Song]
}

class TwitterService extends ITwitterService {

  val NUM_OF_TWEETS = 500

  val BPM_USER = "bpm_playlist"

  val CONSUMER_KEY = "g7yVloTz7oGVj24t5cdTJhMxD"
  val CONSUMER_SECRET = "IvPzpJBsGSRsQFiuwXoCN5nUgquB1Z385yo5jAT4vFEzjE3uaZ"

  val ACCESS_TOKEN = "919943310-nxZesm8w9fmHYXSWvL9LP4xctr0C5sL3Fzxl8iUT"
  val ACCESS_TOKEN_SECRET = "ApOC5trKNX205UWtg3ep1TL2XFDaZhcFQx2EwOhaIowV5"

  val config = new ConfigurationBuilder()
    .setOAuthConsumerKey(CONSUMER_KEY)
    .setOAuthConsumerSecret(CONSUMER_SECRET)
    .setOAuthAccessToken(ACCESS_TOKEN)
    .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET)
    .build

  val paging = {
    val pg = new Paging
    pg.setCount(NUM_OF_TWEETS)
    pg
  }

  val user = "bpm_playlist"

  lazy val tf = new TwitterFactory(config)
  lazy val twitter = tf.getInstance

  def getSongs: Seq[Song] = {
    twitter.getUserTimeline(BPM_USER, paging).map { s => generateSong(s.getText) }.filter( _.isDefined ).map( _.get ).distinct
  }

  def generateSong(term: String): Option[Song] = {
    val pattern = """^([^@#].*) - (.*) playing on #BPM - @sxmElectro$""".r

    val result = pattern.findFirstMatchIn(term).map { x =>
      val artist = x.group(1)
      val title = x.group(2)
      Song(artist, title)
    }

    if (result.isEmpty)
      println(s"'$term' cannot be parsed into a song name!")

    result
  }
} 
开发者ID:DenF923,项目名称:radio-playlist-service,代码行数:62,代码来源:TwitterService.scala

示例5: TwitterInputDStream

//设置package包名称以及导入依赖的类
package com.aluxian.tweeather.streaming

import org.apache.spark.storage.StorageLevel
import org.apache.spark.streaming.StreamingContext
import org.apache.spark.streaming.dstream.ReceiverInputDStream
import org.apache.spark.streaming.receiver.Receiver
import twitter4j.auth.{Authorization, OAuthAuthorization}
import twitter4j.conf.ConfigurationBuilder
import twitter4j.{FilterQuery, Status}


class TwitterInputDStream(@transient ssc: StreamingContext,
                          twitterAuth: Option[Authorization],
                          filterQuery: Option[FilterQuery],
                          storageLevel: StorageLevel
                         ) extends ReceiverInputDStream[Status](ssc) {

  private val authorization = twitterAuth.getOrElse(createOAuthAuthorization())

  private def createOAuthAuthorization(): Authorization = {
    new OAuthAuthorization(new ConfigurationBuilder().build())
  }

  override def getReceiver(): Receiver[Status] = {
    new TwitterReceiver(authorization, filterQuery, storageLevel)
  }

} 
开发者ID:cnajeefa,项目名称:Tourism-Sentiment-Analysis,代码行数:29,代码来源:TwitterInputDStream.scala

示例6: TwitterSimpleWorkerActor

//设置package包名称以及导入依赖的类
package com.crawler.core.actors

import akka.actor.{Actor, ActorRef, Props}
import org.apache.log4j.Logger
import com.crawler.core.actors.twitter.TwitterSequentialTypedWorkerActor.TwitterTypedWorkerTaskRequest
import com.crawler.core.balancers.InitBalancer
import com.crawler.osn.common.{TwitterAccount, TwitterTask}
import com.crawler.osn.twitter.tasks.TwitterTaskUtil
import com.crawler.dao.{KafkaUniqueSaver, KafkaUniqueSaverInfo, _}
import com.crawler.logger.CrawlerLoggerFactory
import com.crawler.util.Util
import twitter4j.conf.ConfigurationBuilder
import twitter4j.{Twitter, TwitterFactory}


object TwitterSimpleWorkerActor {
  def props(twitterAccount: TwitterAccount) = Props(new TwitterSimpleWorkerActor(twitterAccount))
}

class TwitterSimpleWorkerActor(twitterAccount: TwitterAccount) extends Actor {
  val logger = CrawlerLoggerFactory.logger("TwitterSimpleWorkerActor","core/workers")
  var balancer: ActorRef = _
  var twitter: Twitter = buildTwitter(twitterAccount)


  override def receive: Receive = {
    case task: TwitterTask =>
      logger.debug(s"task = $task ${task.getClass}")

      Util.injectDependencies(logger,balancer, task)

      task.run(twitter)
      balancer ! TwitterTypedWorkerTaskRequest(TwitterTaskUtil.getAllTasks(), previousTask = task)

    case InitBalancer() =>
      logger.debug(s"Init balancer with sender=$sender")
      balancer = sender
      balancer ! TwitterTypedWorkerTaskRequest(TwitterTaskUtil.getAllTasks())

    case _ =>
      throw new RuntimeException("World is burning!!")
  }

  def buildTwitter(twitterAccount: TwitterAccount): Twitter = {
    val cb = new ConfigurationBuilder()
    cb.setDebugEnabled(true)
      .setJSONStoreEnabled(true)
      .setOAuthConsumerKey(twitterAccount.key)
      .setOAuthConsumerSecret(twitterAccount.secret)
      .setOAuthAccessToken(twitterAccount.token)
      .setOAuthAccessTokenSecret(twitterAccount.tokenSecret)
    val twitter = new TwitterFactory(cb.build()).getInstance()
    logger.debug(twitter)
    twitter
  }
} 
开发者ID:mxmptv,项目名称:osn.crawler,代码行数:57,代码来源:TwitterSimpleWorkerActor.scala

示例7: main

//设置package包名称以及导入依赖的类
import twitter4j.TwitterFactory
import twitter4j.Twitter
import twitter4j.conf.ConfigurationBuilder

object main {
  def main(args : Array[String]) {

        // (1) config work to create a twitter object
        val cb = new ConfigurationBuilder
        cb.setDebugEnabled(true)
            .setOAuthConsumerKey("wIVFo0g77JTbSuMhk3iC4bHMZ")
            .setOAuthConsumerSecret("YqJIsiaGFIv5cC4Kq9KNfF75emWKivUFvXfgDYEzVoF3ZXm7ik")
            .setOAuthAccessToken("761585594413813760-AfZbuho7fO7yd8S1Z03F0jjNjZPJgZ9")
            .setOAuthAccessTokenSecret("iT1qlhvcPb4uI8Aes7LicPUKtyEG8bbcNURJIG1gB67ut")
        val tf = new TwitterFactory(cb.build)
        val twitter = tf.getInstance

        // (2) use the twitter object to get your friend's timeline
        val statuses = twitter.trends().getAvailableTrends
        
        println("Showing trends.")
        val it = statuses.iterator()
        while (it.hasNext()) {
            val status = it.next
            println(status.getName);
        }
    }

} 
开发者ID:jaquemirandan,项目名称:trabalho_final_jm,代码行数:30,代码来源:main.scala

示例8: TwitterStream

//设置package包名称以及导入依赖的类
package io.gzet.timeseries

import com.google.gson.GsonBuilder
import org.apache.spark.storage.StorageLevel
import org.apache.spark.streaming.twitter.TwitterUtils
import org.apache.spark.streaming.{Minutes, StreamingContext}
import org.apache.spark.{Logging, SparkConf, SparkContext}
import twitter4j.auth.OAuthAuthorization
import twitter4j.conf.ConfigurationBuilder

import scala.util.Try

object TwitterStream extends SimpleConfig with Logging {

  def getTwitterStream(ssc: StreamingContext, filters: Seq[String] = Nil) = {
    val builder = new ConfigurationBuilder()
    builder.setOAuthConsumerKey(twitterApiKey)
    builder.setOAuthConsumerSecret(twitterApiSecret)
    builder.setOAuthAccessToken(twitterTokenKey)
    builder.setOAuthAccessTokenSecret(twitterTokenSecret)
    val configuration = builder.build()
    TwitterUtils.createStream(
      ssc,
      Some(new OAuthAuthorization(configuration)),
      filters,
      StorageLevel.MEMORY_ONLY
    )
  }

  def main(args: Array[String]) = {

    val sparkConf = new SparkConf().setAppName("Twitter Extractor")
    val sc = new SparkContext(sparkConf)
    val ssc = new StreamingContext(sc, Minutes(5))

    val twitterStream = getTwitterStream(ssc, args).mapPartitions({ it =>
      val gson = new GsonBuilder().create()
      it map { s =>
        Try(gson.toJson(s))
      }
    })

    twitterStream
      .filter(_.isSuccess)
      .map(_.get)
      .saveAsTextFiles("twitter")

    // Start streaming context
    ssc.start()
    ssc.awaitTermination()

  }

} 
开发者ID:PacktPublishing,项目名称:Mastering-Spark-for-Data-Science,代码行数:55,代码来源:TwitterStream.scala

示例9: TwitterSentiment

//设置package包名称以及导入依赖的类
import com.databricks.spark.corenlp.functions._
import org.apache.spark._
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.functions.{current_timestamp, explode}
import org.apache.spark.streaming._
import org.apache.spark.streaming.twitter.TwitterUtils
import twitter4j.auth.OAuthAuthorization
import twitter4j.conf.ConfigurationBuilder

object TwitterSentiment {
  System.setProperty("spark.cassandra.connection.host", "127.0.0.1")

  def main(args:Array[String]): Unit = {
    val conf = new SparkConf().setAppName("TwitterSentiment").setMaster("local[*]")

    val spark = SparkSession.builder.config(conf).getOrCreate()

    val ssc = new StreamingContext(spark.sparkContext, Seconds(1))
    // Create a Twitter Stream for the input source.
    val auth = Some(new OAuthAuthorization(new ConfigurationBuilder().build()))
    val twitterStream = TwitterUtils.createStream(ssc, auth, Array("trump", "donald"))

    val tweets = twitterStream
      .filter(tweet => tweet.getLang.equals("en") || tweet.getLang.equals(""))
      .map(_.getText())
      .map(_.replaceAll("/[^A-Za-z0-9 ]/", ""))
      .map(_.replaceAll("/", ""))
      .map(_.replaceAll("RT.+?(?=\\s)\\s", ""))
      .map(_.replaceAll("https([^\\s]+).*", ""))

    tweets.foreachRDD(rdd => {
      import spark.implicits._
      val df = rdd.toDF()

      val output = df.select(cleanxml('value).as('doc))
        .select(explode(ssplit('doc)).as('sen))
        .select('sen, tokenize('sen).as('words), ner('sen).as('nerTags), sentiment('sen).as('sentiment))


      val formated = output
        .drop("words")
        .drop("nerTags")
        .withColumnRenamed("sen", "tweet")
        .withColumn("processed_time", current_timestamp())

      formated
        .write
        .mode("append")
        .format("org.apache.spark.sql.cassandra")
        .options(Map("table" -> "storm_doris", "keyspace" -> "sentiment"))
        .save()

    })

    ssc.start()

    // Let's await the stream to end - forever
    ssc.awaitTermination()
  }
} 
开发者ID:jamescross91,项目名称:sentiment-analysis,代码行数:61,代码来源:TwitterSentiment.scala

示例10: BasicTwitterClient

//设置package包名称以及导入依赖的类
package com.mikemunhall.simpletwitterstats.server.twitter.client

import akka.actor.ActorRef
import com.mikemunhall.simpletwitterstats.Settings
import com.mikemunhall.simpletwitterstats.server.ParsingActor.Parse
import com.typesafe.scalalogging.StrictLogging
import twitter4j._
import twitter4j.conf.ConfigurationBuilder

object BasicTwitterClient {
  def apply(parsingActor: ActorRef, settings: Settings) = new BasicTwitterClient(parsingActor, settings)
}

class BasicTwitterClient(parsingActor: ActorRef, settings: Settings) extends StrictLogging {

  val cb = new ConfigurationBuilder()
  cb.setDebugEnabled(true)
    .setOAuthConsumerKey(settings.Server.Twitter.Client.OAuth.Consumer.key)
    .setOAuthConsumerSecret(settings.Server.Twitter.Client.OAuth.Consumer.secret)
    .setOAuthAccessToken(settings.Server.Twitter.Client.OAuth.Access.token)
    .setOAuthAccessTokenSecret(settings.Server.Twitter.Client.OAuth.Access.secret)

  def simpleStatusListener = new StatusListener() {
    def onStatus(status: Status) = parsingActor ! Parse(status)
    def onDeletionNotice(statusDeletionNotice: StatusDeletionNotice) {}
    def onTrackLimitationNotice(numberOfLimitedStatuses: Int) {}
    def onException(ex: Exception) { ex.printStackTrace }
    def onScrubGeo(arg0: Long, arg1: Long) {}
    def onStallWarning(warning: StallWarning) {}
  }

  val twitterStream = new TwitterStreamFactory(cb.build()).getInstance
  twitterStream.addListener(simpleStatusListener)

  def start = {
    logger.info("Starting Twitter stream")
    twitterStream.sample
  }

  def stop = {
    logger.info("Stopping Twitter stream")
    twitterStream.cleanUp
    twitterStream.shutdown
  }

} 
开发者ID:mmunhall,项目名称:simple-twitter-stats,代码行数:47,代码来源:BasicTwitterClient.scala

示例11: OAuthUtils

//设置package包名称以及导入依赖的类
package org.p7h.spark.sentiment.utils

import twitter4j.auth.OAuthAuthorization
import twitter4j.conf.ConfigurationBuilder


object OAuthUtils {
  def bootstrapTwitterOAuth(): Some[OAuthAuthorization] = {
    System.setProperty("twitter4j.oauth.consumerKey", PropertiesLoader.consumerKey)
    System.setProperty("twitter4j.oauth.consumerSecret", PropertiesLoader.consumerSecret)
    System.setProperty("twitter4j.oauth.accessToken", PropertiesLoader.accessToken)
    System.setProperty("twitter4j.oauth.accessTokenSecret", PropertiesLoader.accessTokenSecret)

    val configurationBuilder = new ConfigurationBuilder()
    val oAuth = Some(new OAuthAuthorization(configurationBuilder.build()))

    oAuth
  }
} 
开发者ID:P7h,项目名称:Spark-MLlib-Twitter-Sentiment-Analysis,代码行数:20,代码来源:OAuthUtils.scala

示例12: TwitterStreamBuilder

//设置package包名称以及导入依赖的类
package models.twitter

import akka.actor.ActorRef
import com.typesafe.config.Config
import twitter4j._
import twitter4j.conf.ConfigurationBuilder

import scala.util.Try

object TwitterStreamBuilder {

  type ReleaseResource = () => Unit

  def startListener(parent: ActorRef, config: Config, hashTags: List[Hashtag]): Option[ReleaseResource] = {
    Try {
      val twitterStream = new TwitterStreamFactory(newConfiguration(config).build()).getInstance()
      twitterStream.addListener(new PokemonTweetListener(parent))
      twitterStream.filter(newHashTagFilter(hashTags))
      () => {
        twitterStream.cleanUp()
        twitterStream.shutdown()
      }
    }.toOption
  }

  private def newConfiguration(implicit config: Config) = {
    new ConfigurationBuilder()
      .setDebugEnabled(true)
      .setOAuthConsumerKey(TwitterCredentials.consumerKey)
      .setOAuthConsumerSecret(TwitterCredentials.consumerSecret)
      .setOAuthAccessToken(TwitterCredentials.accessToken)
      .setOAuthAccessTokenSecret(TwitterCredentials.accessTokenSecret)
  }

  private def newHashTagFilter(hashTags: List[Hashtag]): FilterQuery = {
    import twitter4j.FilterQuery
    new FilterQuery().track(hashTags.map(_.hash).toArray)
  }
}

final class PokemonTweetListener(parent: ActorRef) extends StatusListener {

  def onStatus(status: Status) {
    parent ! PokemonTweet(Author(status.getUser.getScreenName), status.getCreatedAt.getTime, status.getText)
  }

  def onDeletionNotice(statusDeletionNotice: StatusDeletionNotice) {}

  def onTrackLimitationNotice(numberOfLimitedStatuses: Int) {}

  def onException(ex: Exception) {
    parent ! ex
   // ex.printStackTrace()
  }

  def onScrubGeo(arg0: Long, arg1: Long) {}

  def onStallWarning(warning: StallWarning) {}
} 
开发者ID:fagossa,项目名称:poc_rest,代码行数:60,代码来源:TwitterStreamBuilder.scala

示例13:

//设置package包名称以及导入依赖的类
package term.project.SentimentalStats

import twitter4j.TwitterFactory
import twitter4j.conf.ConfigurationBuilder


trait TwitterAuthentication {

  // about as functional as Java setters can be made.
  private val cb = {
    val config = ConfigFile.data.toMap: Map[String, String]

    new ConfigurationBuilder()
      .setDebugEnabled(
        config.getOrElse("Debug Enabled", "true").toBoolean
      )
      .setOAuthConsumerKey(
        config.getOrElse("Oauth Consumer Key", "NoKey")
      )
      .setOAuthConsumerSecret(
        config.getOrElse("Oauth Consumer Secret", "NoSecret")
      )
      .setOAuthAccessToken(
        config.getOrElse("Oauth Access Token", "NoToken")
      )
      .setOAuthAccessTokenSecret(
        config.getOrElse("Oauth Access Secret", "NoToken")
      )
  }

  val twitter = new TwitterFactory(cb.build()).getInstance()
} 
开发者ID:4102,项目名称:Sentimental-Stats,代码行数:33,代码来源:TwitterAuthentication.scala

示例14: TwitterAdapter

//设置package包名称以及导入依赖的类
package helpers

import javax.inject.{Inject, Singleton}

import play.api.Logger
import twitter4j.{OEmbedRequest, Status, Twitter, TwitterFactory}
import twitter4j.conf.ConfigurationBuilder

class TwitterAdapter(
  consumerKey: String, secretKey: String,
  accessToken: String, accessTokenSecret: String,
  cacheDurationInMilli: Long = 5 * 60 * 1000,
  cache: Cache
) {
  private val twitter = new TwitterFactory(
    new ConfigurationBuilder()
      .setOAuthConsumerKey(consumerKey)
      .setOAuthConsumerSecret(secretKey)
      .setOAuthAccessToken(accessToken)
      .setOAuthAccessTokenSecret(accessTokenSecret)
      .build()
  ).getInstance()

  def getLatestTweet(screenName: String): () => Option[Status] = cache.mayBeCached[Option[Status]](
    gen = () => {
      val z: java.util.Iterator[Status] = twitter.getUserTimeline(screenName).iterator
      if (z.hasNext) Some(z.next) else None
    },
    expirationInMillis = Some(cacheDurationInMilli)
  )

  def getLatestTweetEmbed(
    screenName: String, omitScript: Boolean = true, maxWidth: Option[Int] = None
  ): () => Option[(String, java.time.Instant)] = cache.mayBeCached[Option[(String, java.time.Instant)]](
    gen = () => getLatestTweet(screenName)().map { st =>
      val tweetId = st.getId
      val req = new OEmbedRequest(tweetId, "https://twitter.com/" + screenName + "/status/" + tweetId)
      req.setOmitScript(omitScript)
      req.setHideMedia(false)
      maxWidth.foreach { mw => req.setMaxWidth(mw) }
      twitter.getOEmbed(req).getHtml -> java.time.Instant.ofEpochMilli(st.getCreatedAt.getTime)
    },
    expirationInMillis = Some(cacheDurationInMilli)
  )
}

@Singleton
class TwitterAdapterRepo @Inject() (
  cache: Cache
) {
  val logger = Logger(getClass)
  def apply(
    consumerKey: String, secretKey: String,
    accessToken: String, accessTokenSecret: String,
    cacheDurationInMilli: Long = 5 * 60 * 1000
  ) = new TwitterAdapter(
    consumerKey, secretKey, accessToken, accessTokenSecret, cacheDurationInMilli, cache
  )
} 
开发者ID:ruimo,项目名称:store2,代码行数:60,代码来源:TwitterAdapter.scala

示例15: TweeterService

//设置package包名称以及导入依赖的类
package com.example.sbt

import scala.util.Try
import twitter4j.{Twitter, TwitterFactory}
import twitter4j.conf.ConfigurationBuilder

case class TweeterService(client: Twitter) {

  def post(tweet: String): Try[Long] = {
    Try(client.updateStatus(tweet)).map(_.getId)
  }
}

object TweeterService {

  def apply(consumerKey: String, consumerSecret: String, accessToken: String, accessTokenSecret: String): TweeterService = {
    val config = (new ConfigurationBuilder)
      .setOAuthConsumerKey(consumerKey)
      .setOAuthConsumerSecret(consumerSecret)
      .setOAuthAccessToken(accessToken)
      .setOAuthAccessTokenSecret(accessTokenSecret)
      .build()
    val client = new TwitterFactory(config).getInstance()
    TweeterService(client)
  }
} 
开发者ID:Tapad,项目名称:sbt-tweeter,代码行数:27,代码来源:TweeterService.scala


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