将字符串传递给另一个类到查询中

时间:2014-05-21 20:03:04

标签: java string class google-analytics-api

所以这是我向所有JAVA专家提出的问题。我试图将我从属性文件中获取的字符串传递给另一个查询类。对不起,如果这看起来很基本......我真的不知道该怎么做。这是我到目前为止所拥有的

    public class CrunchifyGetPropertyValues {

    public String getPropValues() throws IOException {

        //some code...

        // get the property value and print it out
        String user = prop.getProperty("user");
        String startDate = prop.getProperty("startDate");
        String endDate = prop.getProperty("endDate");
        String values = prop.getProperty("values");

        result = "stuff = " + startDate + ", " + endDate + ", " + values;
        System.out.println(result + "\nProgram Ran on " + time + " by user=" + user);
        return result;
    }

    //this is the code that i thought i needed to connect the strings
    executeDataQuery startConv = new executeDataQuery();
    startConv.executeDataQuery(startDate);
}

这是我的查询,我正在尝试将字符串放入

    private static GaData executeDataQuery(Analytics analytics, String profileId, String newValueData) throws IOException {
    return analytics.data().ga().get("ga:" + profileId, // Table Id. ga: + profile id.
         newValue Data, // Start date: here is where i want to import the strings into
        "2014-05-20", // End date.
        "ga:pageviews,ga:sessions,ga:uniquePageviews") // Metrics.
        .setDimensions("ga:date")
        .setSort("-ga:date")
        .setMaxResults(25)
        .execute();
}

编辑: 所以我改变了一些东西,但我的代码只是带我去了一个新的错误...

try {
  httpTransport = GoogleNetHttpTransport.newTrustedTransport();
  dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
  Analytics analytics = initializeAnalytics();
  String profileId = getFirstProfileId(analytics);
  String newStringValue = getPropValues();
  if (profileId == null) {
    System.err.println("No profiles found.");
  } else {
    GaData gaData = executeDataQuery(analytics, profileId, newStringValue);
    printGaData(gaData);
  }
//lots of other code

我在String中添加了新的StringValue = getPropValues()...它表示该方法无法定义...任何帮助?

1 个答案:

答案 0 :(得分:0)

将您的签名(第二种方法' head')扩展为: private static GaData executeDataQuery(Analytics analytics, String profileId, String newStringValue) throws IOException {并在其中使用newStringValue

在第一个代码中,只需拨打executeDataQuery(first, second, newStringValue)