Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在没有JAVA web浏览器的情况下验证Google Analytics_Java_Authentication_Google Analytics_Oauth 2.0 - Fatal编程技术网

在没有JAVA web浏览器的情况下验证Google Analytics

在没有JAVA web浏览器的情况下验证Google Analytics,java,authentication,google-analytics,oauth-2.0,Java,Authentication,Google Analytics,Oauth 2.0,我目前有一个谷歌分析程序从我的网站上提取一些分析数据。目前它位于我的本地机器上,运行良好。不过,我想将该程序移到我们的Oracle云服务器中,该服务器承载我的web文件。它是一个基于linux的服务器,几乎不支持浏览器。我试着在服务器上运行这个程序,但和往常一样,它会提示我去一个网站验证Oauth..etc.ect () 我尝试在服务器上使用web浏览器…效果不太好。我想知道是否有人有解决方案可以让我使用这个应用程序而不必使用web浏览器进行身份验证 编辑:在服务Acc方面有困难 所以。。。我在

我目前有一个谷歌分析程序从我的网站上提取一些分析数据。目前它位于我的本地机器上,运行良好。不过,我想将该程序移到我们的Oracle云服务器中,该服务器承载我的web文件。它是一个基于linux的服务器,几乎不支持浏览器。我试着在服务器上运行这个程序,但和往常一样,它会提示我去一个网站验证Oauth..etc.ect

()

我尝试在服务器上使用web浏览器…效果不太好。我想知道是否有人有解决方案可以让我使用这个应用程序而不必使用web浏览器进行身份验证

编辑:在服务Acc方面有困难

所以。。。我在我当前的应用程序中有这个来获得授权

     /** Authorizes the installed application to access user's protected data. */
  private static Credential authorize() throws Exception {
    // load client secrets
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(
        JSON_FACTORY, new InputStreamReader(
            extractanalyticsgoogleapi.class.getResourceAsStream("/client_secrets.json")));
    if (clientSecrets.getDetails().getClientId().startsWith("Enter")
        || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
      System.out.println(
          "Enter Client ID and Secret from https://code.google.com/apis/console/?api=analytics "
          + "into analytics-cmdline-sample/src/main/resources/client_secrets.json");
      System.exit(1);
    }
    // set up authorization code flow
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
        httpTransport, JSON_FACTORY, clientSecrets,
        Collections.singleton(AnalyticsScopes.ANALYTICS_READONLY)).setDataStoreFactory(
        dataStoreFactory).build();
    // authorize
    return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
  }

我不确定我会把服务Acc代码放在哪里,你要做的是建立一个授权访问你的谷歌分析数据的数据库。 这允许您的服务器代码访问您的谷歌分析信息

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.analytics.AnalyticsScopes;

// ...

String emailAddress = "123456789000-abc123def456@developer.gserviceaccount.com";
JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
GoogleCredential credential = new GoogleCredential.Builder()
    .setTransport(httpTransport)
    .setJsonFactory(JSON_FACTORY)
    .setServiceAccountId(emailAddress)
    .setServiceAccountPrivateKeyFromP12File(new File("MyProject.p12"))
    .setServiceAccountScopes(Collections.singleton(AnalyticsScopes.ANALYTICS_READONLY))
    .build();

curl可能是一个解决方案。您是对的,curl不是Java的最佳选择:。我从未接触过Java,所以这是一个无知的建议。你要做的是建立一个服务帐户。