【问题标题】:How to access Google plus domains api using GoogleApiClient object?如何使用 GoogleApiClient 对象访问 Google plus 域 API?
【发布时间】:2015-05-13 14:10:14
【问题描述】:

文档here 说明如下

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

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

【问题讨论】:

    标签: android api google-plus google-api-client google-plus-domains


    【解决方案1】:

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

    最重要的是:“Domain 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 link 完成示例。

    【讨论】:

    • 奇怪,看来我可以使用常规的 Google+ API 身份验证来使用 Google API Explorer 上的 Google+ Domains API。那么,也许这会起作用?
    猜你喜欢
    • 2020-02-22
    • 1970-01-01
    • 2015-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-01
    相关资源
    最近更新 更多