0

这里的文档说以下

警告:Google+ 登录使用的 Google+ 登录按钮和 plus.login 范围目前不支持与 Google+ Domains API 一起使用。使用授予 https://www.googleapis.com/auth/plus.login范围的身份验证令牌向 Google+ Domains API 发出的请求或由 Google+ 登录按钮生成的请求将失败。

因此,如果我们需要访问 Google Plus Domains API,我们如何在 android 中使用GoogleApiClient对象呢?我想要一个需要使用 Domains API 的用户圈子列表。

4

1 回答 1

0

考虑使用 GoogleAuthUtil 进行 Google Plus 域身份验证。

最重要的是:“域 API 仅适用于域电子邮件 id”(不是 gmail id)。

String scopes = "oauth2:" + "https://www.googleapis.com/auth/plus.me " +
            "https://www.googleapis.com/auth/plus.circles.read";  
String accountName = "domain_email_id_used_for_login";//fetch from AccountManager or ask the user to enter
String token = "";
try {
        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this);
        token = sharedPref.getString("token", "");
        if (!token.equals("")) {
            GoogleAuthUtil.clearToken(LoginActivity.this, token);
        }
        token = GoogleAuthUtil.getToken(LoginActivity.this,
                        accountName, scopes);
        GoogleCredential googleCredential = new GoogleCredential().setAccessToken(token);
        PlusDomains plusDomains = new PlusDomains.Builder(new NetHttpTransport(), new JacksonFactory(), googleCredential).setApplicationName("GPlusLab").build();
        plusDomains.people().get("me").execute();
                return token;
    } catch (UserRecoverableAuthException e) {
                startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
    } catch (GoogleAuthException e) {
                e.printStackTrace();
    } catch (IOException e) {
                e.printStackTrace();
    }

完成示例的github 链接。

于 2015-04-13T07:48:58.113 回答