1

我正在嘗試將Java Analytics API用於Google Analytics API。我下載了API的客戶端庫的最新版本,並且似乎擁有我需要的所有其他軟件包。我的問題是,作爲Analytics API tutorial的一部分,Google提供的示例代碼使用Analytics.builder()方法(見下面的代碼),但該方法似乎不在Analytics類中。有任何想法嗎?提前致謝。Google AnalyticsAPI:Analytics.builder方法在哪裏?

/* 
* Google Analytics API test. 
*/ 
package helloanalyticsapi; 

import com.google.api.client.auth.oauth2.*; 
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver; 
//import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessProtectedResource; 
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.analytics.Analytics; 
import com.google.api.services.analytics.AnalyticsScopes; 
//import com.google.api.services.oauth2.*; 
import java.util.Arrays; 
/** 
* 
* @author basset 
*/ 
public class HelloAnalyticsApi { 

    // Global instance of the HTTP transport. 
    private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); 

    // Global instance of the JSON factory. 
    private static final JsonFactory JSON_FACTORY = new JacksonFactory(); 

    private static Analytics initializeAnalytics() throws Exception { 
     Credential credential = OAuth2Native.authorize(
     HTTP_TRANSPORT, JSON_FACTORY, new LocalServerReceiver(), 
     Arrays.asList(AnalyticsScopes.ANALYTICS_READONLY)); 

     Analytics analytics; 
     analytics = Analytics.builder(HTTP_TRANSPORT, JSON_FACTORY) 
      .setApplicationName("Hello-Analytics-API-Sample") 
      .setHttpRequestInitializer(credential) 
      .build(); 

     return analytics; 

    } 

    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String[] args) { 


    } 
} 

回答

3

看起來像是被刪除,你現在有

Analytics analytics = new Analytics(HTTP_TRANSPORT, JSON_FACTORY, credential)

的教程超過一歲,似乎沒有跟上圖書館的步伐,以取代構建鏈。

0

我在com.google.api.services.analytics.Analytics中有Analytics.Builder()方法我正在使用GA v3