本文整理汇总了Scala中com.google.api.client.json.jackson2.JacksonFactory类的典型用法代码示例。如果您正苦于以下问题:Scala JacksonFactory类的具体用法?Scala JacksonFactory怎么用?Scala JacksonFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JacksonFactory类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: Googlemonitoringapiworks
//设置package包名称以及导入依赖的类
package com.berkgokden
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential
import com.google.api.client.http.javanet.NetHttpTransport
import com.google.api.client.json.jackson2.JacksonFactory
import com.google.api.services.monitoring.v3.{Monitoring, MonitoringScopes}
object Googlemonitoringapiworks extends App {
println("Hello, google-monitoring-api-works")
val project = "your-project-name" // you should have one on google.
val projectResource = "projects/" + project
// Grab the Application Default Credentials from the environment.
// Download authentication json form Google Cloud and Put conf.json into resources folder!
val resourceAsStream = getClass.getResourceAsStream("/conf.json")
println("ok")
val credential = GoogleCredential.fromStream(resourceAsStream)
.createScoped(MonitoringScopes.all())
println(credential.getServiceAccountId) // this only works if you have a service account
// Create and return the CloudMonitoring service object
val httpTransport = new NetHttpTransport()
val jsonFactory = new JacksonFactory()
val service = new Monitoring.Builder(httpTransport,
jsonFactory, credential)
.setApplicationName("Monitoring Sample")
.build()
val res = service.projects().metricDescriptors().list(projectResource).execute()
println(res.toPrettyString)
}
开发者ID:bgokden,项目名称:google-monitoring-api-works,代码行数:34,代码来源:Googlemonitoringapiworks.scala
示例2: Helper
//设置package包名称以及导入依赖的类
package io.taig.sbt.googleplay
import java.io.File
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport
import com.google.api.client.json.jackson2.JacksonFactory
import com.google.api.services.androidpublisher.{ AndroidPublisher, AndroidPublisherScopes }
import scala.collection.JavaConversions._
object Helper {
lazy val HttpTransport = GoogleNetHttpTransport.newTrustedTransport
lazy val JsonFactory = JacksonFactory.getDefaultInstance
def authorize( applicationName: String, serviceAccount: String, serviceAccountPrivateKey: File ): AndroidPublisher = {
val credentials = new GoogleCredential.Builder()
.setTransport( HttpTransport )
.setJsonFactory( JsonFactory )
.setServiceAccountId( serviceAccount )
.setServiceAccountScopes( List( AndroidPublisherScopes.ANDROIDPUBLISHER ) )
.setServiceAccountPrivateKeyFromP12File( serviceAccountPrivateKey )
.build
new AndroidPublisher.Builder( HttpTransport, JsonFactory, credentials )
.setApplicationName( applicationName )
.build
}
}
开发者ID:Taig,项目名称:sbt-googleplay,代码行数:31,代码来源:Helper.scala
示例3: Hello
//设置package包名称以及导入依赖的类
package com.ru.waka
import java.io.File
import java.net.URL
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport
import com.google.api.client.json.jackson2.JacksonFactory
import com.google.gdata.client.spreadsheet.SpreadsheetService
import com.google.gdata.data.Feed
import com.google.gdata.data.docs.SpreadsheetEntry
import com.google.gdata.data.spreadsheet.SpreadsheetFeed
import scala.collection.JavaConverters._
object Hello {
private val jsonFactory = new JacksonFactory
private val transport = GoogleNetHttpTransport.newTrustedTransport()
private val service = new SpreadsheetService(this.getClass.getName)
private val scopes = Seq(
"https://www.googleapis.com/auth/drive.file",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile",
"https://docs.google.com/feeds",
"https://spreadsheets.google.com/feeds"
).asJava
def main (args: Array[String] ) {
val c = new GoogleCredential.Builder()
.setTransport(transport)
.setJsonFactory(jsonFactory)
.setServiceAccountId("[email protected]")
.setServiceAccountPrivateKeyFromP12File(new File("./hubot-dark-6e8b3857b0b0.p12"))
.setServiceAccountScopes(scopes)
.build()
c.refreshToken()
service.setOAuth2Credentials(c)
val e = service.getFeed(new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full"), classOf[SpreadsheetFeed])
println(e.getAuthors)
println(e.getTitle.getPlainText)
}
}
开发者ID:ara-ta3,项目名称:googlespreadsheet-sample,代码行数:47,代码来源:Hello.scala
示例4: DefaultSource
//设置package包名称以及导入依赖的类
package com.logicstack.spark
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport
import com.google.api.client.json.jackson2.JacksonFactory
import com.google.api.services.analyticsreporting.v4.AnalyticsReporting
import org.apache.spark.sql.SQLContext
import org.apache.spark.sql.sources.{BaseRelation, RelationProvider, SchemaRelationProvider}
import org.apache.spark.sql.types.StructType
class DefaultSource extends SchemaRelationProvider {
private val httpTransport = GoogleNetHttpTransport.newTrustedTransport
private val jsonFactory = JacksonFactory.getDefaultInstance
override def createRelation(sqlContext: SQLContext, parameters: Map[String, String], schema: StructType): ReportRelation = {
val clientId = parameters("clientId")
val clientSecret = parameters("clientSecret")
val accessToken = parameters("accessToken")
val refreshToken = parameters("refreshToken")
val credential = new GoogleCredential.Builder()
.setJsonFactory(jsonFactory)
.setTransport(httpTransport)
.setClientSecrets(clientId, clientSecret)
.build()
.setAccessToken(accessToken)
.setRefreshToken(refreshToken)
val analyticsReporting = new AnalyticsReporting.Builder(httpTransport, jsonFactory, credential)
.setApplicationName("spark-ga")
.build()
new ReportRelation(
analyticsReporting,
parameters("profile"),
parameters("startDate"),
parameters("endDate"),
schema
)(sqlContext)
}
}
开发者ID:logicstack,项目名称:spark-ga,代码行数:44,代码来源:DefaultSource.scala
示例5: OcrTest
//设置package包名称以及导入依赖的类
import java.io.FileInputStream
import java.io.File
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport
import com.google.api.client.json.jackson2.JacksonFactory
import com.google.api.services.vision.v1.model._
import com.google.api.services.vision.v1.{Vision, VisionScopes}
import com.google.common.collect.ImmutableList
import java.nio.file.{Files}
import ocr.model.OcrTextAnnotation
object OcrTest {
def main2(args: Array[String]): Unit = {
val credential =
GoogleCredential
.fromStream(new FileInputStream(new File("/home/leonti/development/google-cloud/Receipts-dev-ocr-service-account.json")))
.createScoped(VisionScopes.all())
val jsonFactory = JacksonFactory.getDefaultInstance
val vision = new Vision.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, credential)
.setApplicationName("Receipts")
.build()
val requests: ImmutableList.Builder[AnnotateImageRequest] = ImmutableList.builder()
requests.add(
new AnnotateImageRequest()
.setImage(
new Image().encodeContent(Files.readAllBytes(new File("/home/leonti/development/document-scanner/images/7.jpg").toPath)))
.setFeatures(ImmutableList.of(new Feature()
.setType("TEXT_DETECTION")
.setMaxResults(100))))
val annotate =
vision
.images()
.annotate(new BatchAnnotateImagesRequest().setRequests(requests.build()))
// Due to a bug: requests to Vision API containing large images fail when GZipped.
annotate.setDisableGZipContent(true)
val batchResponse = annotate.execute()
val response = batchResponse.getResponses().get(0)
val annotations = response.getTextAnnotations
println(response.getFullTextAnnotation.toPrettyString)
val fullAnnotation = OcrTextAnnotation.fromTextAnnotation(response.getFullTextAnnotation)
println(fullAnnotation)
}
}
开发者ID:Leonti,项目名称:receipts-rest-service,代码行数:56,代码来源:OcrTest.scala
示例6: AppModule
//设置package包名称以及导入依赖的类
package conf
import java.time.{Clock, ZoneId}
import akka.actor.{Actor, ActorRef, Props}
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier
import com.google.api.client.http.javanet.NetHttpTransport
import com.google.api.client.json.jackson2.JacksonFactory
import com.google.api.client.util.store.AbstractDataStoreFactory
import com.google.inject.AbstractModule
import com.google.inject.name.Names
import com.google.inject.util.Providers
import controllers.AppController
import play.api.libs.concurrent.{Akka, AkkaGuiceSupport}
import services._
import services.support.SystemClock
import scala.reflect.ClassTag
class AppModule extends AbstractModule {
def configure = {
bind(classOf[AppController]).asEagerSingleton // in prod mode all dependencies of AppController get built at startup time
bind(classOf[AbstractDataStoreFactory]).to(classOf[RepositoryDataStoreFactory])
bind(classOf[GoogleIdTokenVerifier]).toInstance(new GoogleIdTokenVerifier.Builder(new NetHttpTransport, new JacksonFactory).build)
bind(classOf[Clock]).toInstance(new SystemClock(ZoneId.systemDefault()))
}
}
class AkkaModule extends AbstractModule with AkkaGuiceSupport {
def configure = {
bindActorNoEager[SuperSupervisorActor](SuperSupervisorActor.actorName)
bindActorFactory[UserSupervisorActor, UserSupervisorActor.Factory]
}
private def bindActorNoEager[T <: Actor : ClassTag](name: String, props: Props => Props = identity): Unit = {
binder.bind(classOf[ActorRef])
.annotatedWith(Names.named(name))
.toProvider(Providers.guicify(Akka.providerOf[T](name, props)))
}
}
开发者ID:phdezann,项目名称:connectus,代码行数:41,代码来源:Module.scala
示例7: GoogleAuthorization
//设置package包名称以及导入依赖的类
package services
import java.io.StringReader
import javax.inject.{Inject, Singleton}
import conf.AppConf
import com.google.api.client.auth.oauth2.Credential
import com.google.api.client.auth.openidconnect.IdTokenResponse
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow.Builder
import com.google.api.client.googleapis.auth.oauth2.{GoogleAuthorizationCodeFlow, GoogleAuthorizationCodeTokenRequest, GoogleClientSecrets, GoogleTokenResponse}
import com.google.api.client.http.javanet.NetHttpTransport
import com.google.api.client.json.jackson2.JacksonFactory
import com.google.api.client.util.store.AbstractDataStoreFactory
import com.google.api.services.gmail.Gmail
import com.google.api.services.gmail.GmailScopes._
import com.google.common.collect.Lists._
import common._
import scala.concurrent.{ExecutionContext, Future}
object GoogleAuthorization {
val ApplicationName = "Connectus"
val Scopes = newArrayList(GMAIL_COMPOSE, GMAIL_MODIFY)
val transport = new NetHttpTransport
val factory = new JacksonFactory
}
@Singleton
class GoogleAuthorization @Inject()(implicit exec: ExecutionContext, appConf: AppConf, dataStoreFactory: AbstractDataStoreFactory) {
private def loadSecrets: GoogleClientSecrets =
GoogleClientSecrets.load(GoogleAuthorization.factory, new StringReader(appConf.getGoogleClientSecret))
private lazy val flow: GoogleAuthorizationCodeFlow = new Builder(GoogleAuthorization.transport, GoogleAuthorization.factory, loadSecrets, GoogleAuthorization.Scopes) //
.setDataStoreFactory(dataStoreFactory)
.setAccessType("offline") // So we can get a refresh and access the protected service while the user is gone
.setApprovalPrompt("auto").build
def addCredentials(userId: String, refreshToken: String) = {
val tokenResponse: IdTokenResponse = new IdTokenResponse
tokenResponse.setRefreshToken(refreshToken)
flow.createAndStoreCredential(tokenResponse, userId)
}
def convert(authorisationCode: String): Future[GoogleTokenResponse] = {
val request: GoogleAuthorizationCodeTokenRequest = flow.newTokenRequest(authorisationCode)
// as specified in https://developers.google.com/identity/protocols/CrossClientAuth, the redirect_uri argument must be equal to null
request.set("redirect_uri", null)
Future {concurrent.blocking {request.execute()}}
}
def getService(accountId: String): Future[Gmail] =
Future {concurrent.blocking {Option(flow.loadCredential(accountId))}}
.flatMap(fromOption(_))
.map(gmail(_))
private def gmail(credential: Credential): Gmail =
new Gmail.Builder(GoogleAuthorization.transport, GoogleAuthorization.factory, credential).setApplicationName(GoogleAuthorization.ApplicationName).build
}
开发者ID:phdezann,项目名称:connectus,代码行数:60,代码来源:GoogleAuthorization.scala
示例8: BigQueryClient
//设置package包名称以及导入依赖的类
package com.example.prodspark.client
import java.io.IOException
import com.example.prodspark.util.RetryUtil
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential
import com.google.api.client.http.javanet.NetHttpTransport
import com.google.api.client.json.jackson2.JacksonFactory
import com.google.api.services.bigquery.{Bigquery, BigqueryScopes}
import com.google.api.services.bigquery.model._
import com.google.cloud.hadoop.io.bigquery.BigQueryStrings
import org.slf4j.LoggerFactory
import scala.collection.JavaConverters._
object BigQueryClient {
private val SCOPES = List(BigqueryScopes.BIGQUERY).asJava
private val bigquery: Bigquery = {
val credential = GoogleCredential.getApplicationDefault.createScoped(SCOPES)
new Bigquery.Builder(new NetHttpTransport, new JacksonFactory, credential)
.setApplicationName("spark-bigquery")
.build()
}
def streamingInsert(
rows: Seq[TableDataInsertAllRequest.Rows],
tableSpec: String,
projectId: String
): Unit = {
lazy val tableRef = BigQueryStrings.parseTableReference(tableSpec)
val req = new TableDataInsertAllRequest()
.setRows(rows.asJava)
.setIgnoreUnknownValues(true)
RetryUtil.retry(3) {
val response = insertAll(tableRef, req)
if (response.getInsertErrors != null) {
log.error("Error inserting into BigQuery: " + response.getInsertErrors.toString)
throw new IOException(response.getInsertErrors.toString)
}
}
}
private val log = LoggerFactory.getLogger(this.getClass)
}
开发者ID:rvenkatesh25,项目名称:spark-streaming-gcp,代码行数:49,代码来源:BigQueryClient.scala
示例9: GoogleContainerEngine
//设置package包名称以及导入依赖的类
package io.incube.blue
import java.io.ByteArrayInputStream
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport
import com.google.api.client.http.{HttpRequest, HttpRequestInitializer}
import com.google.api.client.json.jackson2.JacksonFactory
import com.google.api.services.container.{Container, ContainerScopes}
object GoogleContainerEngine {
val jsonFactory = JacksonFactory.getDefaultInstance
val httpTransport = GoogleNetHttpTransport.newTrustedTransport() //TODO: handle exceptions
//TODO: abstract this away
val serviceAccount = new ByteArrayInputStream("{\n \"type\": \"service_account\",\n \"project_id\": \"gcp-client-0\",\n \"private_key_id\": \"5b5a03aab0c47c9d200fe660b716341a38030b93\",\n \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC1kmgkZowaxW0t\\nP3httySW6Fc3qCIboJhpaoCPnesPrWQhNR7cpJjauwxqzr6Di7O7fbRC7Y4e9Bjv\\nclD1vK2U842ZLREkMaFG7RMi2lMtmzJlsYyEP/BEHe/YxqjrxtlaH9KeVCwTpzWl\\nttpaXxNsF2jc6EQT/vuYBS2ru9tJGrfh+i+6ILlPMQhXw/tcea7phbGPAWI4ZFcY\\nMpAtn0Jf4h6GNs6CfrMzOQqwY8OEmDqZZDmN1uwYTzbEokYcSx+Emji/3h7KEKGk\\nZ/72/zHQDkK43JtrrIvz1yuzsgmct1qA3RuygQujf7GDZ8TkAPAxp+/Q//nw9V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6TGS3UDjWnJpgorEW7yzDWAX5zkCDoj9kQKBgHPzaKbywanRmNtEKH8k\\nL7F2Xux8TstRv/kFqiGSIWuxRVP/0zcKRCpGtQsceYcJGbCwD15D8oOnA9FcVYw8\\nM+pHf+eXZJldJHX8Kiegmv1ZsDd9a2rKiZGNlmnh9wjc/lsHrcCu539TNu/beXNH\\naJUIF4V+GHDuPhQciDmEhM3y\\n-----END PRIVATE KEY-----\\n\",\n \"client_email\": \"[email protected]\",\n \"client_id\": \"100218978202688694903\",\n \"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\",\n \"token_uri\": \"https://accounts.google.com/o/oauth2/token\",\n \"auth_provider_x509_cert_url\": \"https://www.googleapis.com/oauth2/v1/certs\",\n \"client_x509_cert_url\": \"https://www.googleapis.com/robot/v1/metadata/x509/postman%40gcp-client-0.iam.gserviceaccount.com\"\n}".getBytes)
final private val container = new Container(httpTransport, jsonFactory, new HttpRequestInitializer {
override def initialize(request: HttpRequest): Unit = {
GoogleCredential.fromStream(serviceAccount).createScoped(ContainerScopes.all).initialize(request)
}
})
def instance = container
}
开发者ID:incube-io,项目名称:blue,代码行数:26,代码来源:GoogleContainerEngine.scala
注:本文中的com.google.api.client.json.jackson2.JacksonFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论