使用Google服务帐户java的Youtube Data API v3

时间:2014-08-01 06:19:00

标签: java youtube youtube-api youtube-data-api jwt

我正在使用#google服务帐户在我的网站中集成视频上传功能,而我正在使用Youtube Data api v3 java库。

当我运行以下代码时,它给了我运行时异常。请帮帮我..先谢谢你..

这是我的java代码..

package com.a2z.integration.youtube;


import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.api.services.youtube.YouTube;

import com.google.api.services.youtube.YouTube.Activities;
import java.io.File;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/**
 *
 * @author sunil
 */
public class ServiceAuthToken
{
   final static HttpTransport TRANSPORT = new NetHttpTransport();
    static JsonFactory JSON_FACTORY = new JacksonFactory();

   public static void main(String []g) throws Exception
   {
      List<String>scops = new <String>ArrayList();
      scops.add("https://www.googleapis.com/auth/youtube");

      GoogleCredential credential = new GoogleCredential.Builder()
      .setTransport(TRANSPORT)
      .setJsonFactory(JSON_FACTORY)
      .setServiceAccountId(Constants.SERVICE_ACCOUNT_ID)
      .setServiceAccountScopes(scops)
      .setServiceAccountPrivateKeyFromP12File(new File("key.p12"))
      //.setClientSecrets("*******.apps.googleusercontent.com","")
      .setClientSecrets(GoogleClientSecrets.load(JSON_FACTORY,new InputStreamReader(java.io.Reader.class.getResourceAsStream("client_secrets.json"))))
      .build();

      YouTube youtube =  new YouTube.Builder(TRANSPORT, JSON_FACTORY,credential).setApplicationName("gleaming-scene-655").build();

      Activities act = youtube.activities();
      Activities.List list = act.list("s");
   }
}

我在控制台中收到的异常:

run:
Exception in thread "main" java.lang.NoSuchMethodError: org.codehaus.jackson.JsonFactory.configure(Lorg/codehaus/jackson/JsonGenerator$Feature;Z)Lorg/codehaus/jackson/JsonFactory;
    at com.google.api.client.json.jackson.JacksonFactory.<init>(JacksonFactory.java:48)
    at com.a2z.integration.youtube.ServiceAuthToken.<clinit>(ServiceAuthToken.java:28)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

0 个答案:

没有答案