2

我在 google plus 文档中看到用户有封面照片。

所以这里是我如何构建一个我认为有足够权限的 api 客户端并获取当前人的封面照片以及其他信息的要点。

private static final String SCOPE_EMAIL =
    "https://www.googleapis.com/auth/plus.profile.emails.read";

private GoogleApiClient buildGoogleApiClient() {
    return new GoogleApiClient.Builder(this)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .addApi(Plus.API, Plus.PlusOptions.builder().build())
        .addScope(Plus.SCOPE_PLUS_LOGIN)
        .addScope(new Scope(SCOPE_EMAIL))
        .addScope(Plus.SCOPE_PLUS_PROFILE).build();
}

private User createUserFromGoogle() {
    _googleApiClient = buildGoogleApiClient();

    Person currentUser = Plus.PeopleApi.getCurrentPerson(_googleApiClient);
    String userUID = GOOGLE_UID_PREFIX + currentUser.getId();
    String firstName = currentUser.getName().getGivenName();
    String lastName = currentUser.getName().getFamilyName();
    String email = Plus.AccountApi.getAccountName(_googleApiClient);
    String profileURL = getLargeImageURL(currentUser);
    Person.Cover cover = currentUser.getCover();
    String coverURL = null;
    Timber.e("has cover:" + currentUser.hasCover());
    if (cover != null) {
        CoverPhoto coverPhoto = cover.getCoverPhoto();
        if (coverPhoto != null) {
            coverURL = coverPhoto.getUrl();
        }
    }
    //Create a new {@link User} with empty groups, contacts, and channels
    Id id = Id.builder().value(userUID).build();
    return User.create(id, firstName, lastName, email, profileURL, coverURL, null, null, null);
}

createUserFromGoogle()当我们在ConnectionCallbacks. 每次,hasCover()总是返回 false,并且Cover总是为 null。有人成功下载了coverPhoto URL吗?所有其他信息均已成功检索。

4

0 回答 0