[工作记录]Google服务接入基础流程

/ 0评 / 0

Google服务封装好的sdk地址

https://github.sheincorp.cn/googleapis/google-api-java-client-services/tree/main/clients

Google服务使用之前得先认证

implementation 'com.google.auth:google-auth-library-oauth2-http:1.19.0'

基础使用方法

public class GooglePlayDeveloperAPI {

    private static final String API_KEY = "api-xxxxx-xxxxx.json";

    public static void main(String[] args) {
        try {
            GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream(API_KEY))
                    .createScoped(PlaydeveloperreportingScopes.all());
            credentials.refreshIfExpired();
            AccessToken token = credentials.getAccessToken();

            HttpRequestInitializer requestInitializer = httpRequest -> {
            //jwt认证
                httpRequest.getHeaders().setAuthorization("Bearer " + token.getTokenValue());
            };
            //选择的Google服务库
            Playdeveloperreporting build = new Playdeveloperreporting.Builder(new NetHttpTransport(), GsonFactory.getDefaultInstance(), requestInitializer).setApplicationName("应用包名").build();
           GooglePlayDeveloperReportingV1beta1AnrRateMetricSet execute = build.vitals().anrrate().get("apps/应用包名/anrRateMetricSet").execute();
            System.out.println(execute);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注