1

我正在尝试使用 Google Plus Domain API Android 获取用户圈子。

我首先在我的项目中导入了以下库:

google-api-client-1.18.0-rc.jar
google-api-client-android-1.18.0-rc.jar
google-oauth-client-1.18.0-rc.jar
google-http-client-1.18.0-rc.jar
google-http-client-android-1.18.0-rc.jar
gson-2.1.jar
jackson-core-asl-1.9.11.jar
jackson-core-2.1.3.jar
jsr305-1.3.9.jar
protobuf-java-2.4.1.jar

请找到链接以获取更多信息。

我做了以下步骤:

  1. 获取身份验证令牌:

    String accountName = params[0];
    String GPLUS_PROFILE = "https://www.googleapis.com/auth/userinfo.profile";
    String GPLUS_LOGIN = "https://www.googleapis.com/auth/plus.login";
    String GPLUS_CIRCLES = "https://www.googleapis.com/auth/plus.circles.read";
    String GPLUS_ME = "https://www.googleapis.com/auth/plus.me";
    String scopes = "oauth2:" + GPLUS_PROFILE + " " + GPLUS_LOGIN + " "
            + GPLUS_CIRCLES + " " + GPLUS_ME;
    String token = null;
    try {
        token = GoogleAuthUtil.getToken(LoginActivity.this,
                accountName, scopes);
        return token;
    } catch (IOException e) {
        Log.e(TAG, e.getMessage());
    } catch (UserRecoverableAuthException e) {
        startActivityForResult(e.getIntent(), REQ_SIGN_IN_REQUIRED);
        return null;
    } catch (GoogleAuthException e) {
        Log.e(TAG, e.getMessage());
    }
    
  2. 现在,当我收到身份验证令牌时,我尝试创建 PlusDomain 类对象以获取有关用户的详细信息:

    public void getPlusDomain(String response) {
        HttpTransport httpTransport = new NetHttpTransport();
        JsonFactory jsonFactory = new JacksonFactory();
    
        GoogleCredential googleCredential = new GoogleCredential()
                .setAccessToken(response);
        plusDomains = new PlusDomains.Builder(httpTransport, jsonFactory,
                googleCredential).setApplicationName("Google  Mini")
                .build();
        Person mePerson;
        try {
            mePerson = plusDomains.people().get("me").execute();
            System.out.println("ID:\t" + mePerson.getId());
            System.out.println("Display Name:\t" + mePerson.getDisplayName());
            System.out.println("Image URL:\t" + mePerson.getImage().getUrl());
            System.out.println("Profile URL:\t" + mePerson.getUrl());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    

我得到以下异常:

例外

我使用此链接解决问题,但异常发生

 JsonFactory jsonFactory = new JacksonFactory();
        Thread.currentThread().setContextClassLoader(
                jsonFactory.getClass().getClassLoader());

但是在那之后我得到了

com.google.api.client.googleapis.json.GoogleJsonResponseException

如何解决这个问题以及为什么会出现这个异常

在此处输入图像描述

4

0 回答 0