wfansh 6 mesi fa
parent
commit
2aebd0a92d

+ 1 - 1
src/main/java/com/wechi/adweb/bridge/google/analytics/GADataService.java

@@ -123,7 +123,7 @@ public class GADataService {
             RunReportResponse response = analyticsDataClient.runReport(request.build());
 
             // Converts and returns.
-            return toReportData(response.getRowsList(), reportRequest);
+            return toReport(response.getRowsList(), reportRequest);
         } catch (IOException e) {
             log.error(e.getMessage());
             throw new DataException(e);

+ 8 - 6
src/main/java/com/wechi/adweb/bridge/google/gtm/service/GTMService.java

@@ -1,11 +1,11 @@
 package com.wechi.adweb.bridge.google.gtm.service;
 
-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.gson.GsonFactory;
 import com.google.api.services.tagmanager.TagManager;
 import com.google.api.services.tagmanager.TagManagerScopes;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.GoogleCredentials;
 
 import lombok.extern.slf4j.Slf4j;
 
@@ -32,16 +32,18 @@ public class GTMService {
     @PostConstruct
     private void init() throws GeneralSecurityException, IOException {
         // Service account authorization;
-        HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
-        GoogleCredential credential =
-                GoogleCredential.fromStream(
+        GoogleCredentials credentials =
+                GoogleCredentials.fromStream(
                                 this.getClass()
                                         .getClassLoader()
                                         .getResourceAsStream(serviceAccountKey))
                         .createScoped(TagManagerScopes.all());
 
         this.tagManager =
-                new TagManager.Builder(httpTransport, GsonFactory.getDefaultInstance(), credential)
+                new TagManager.Builder(
+                                GoogleNetHttpTransport.newTrustedTransport(),
+                                GsonFactory.getDefaultInstance(),
+                                new HttpCredentialsAdapter(credentials))
                         .build();
     }
 }

+ 1 - 6
src/test/java/com/wechi/adweb/bridge/DataBridgeApplicationTests.java

@@ -1,16 +1,11 @@
 package com.wechi.adweb.bridge;
 
-import com.wechi.adweb.bridge.google.analytics.GAAdminService;
-
 import org.junit.jupiter.api.Test;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 
 @SpringBootTest
 class DataBridgeApplicationTests {
 
-    @Autowired GAAdminService gaAdminService;
-
     @Test
-    void contextLoads() throws Exception {}
+    void contextLoads() {}
 }