gpt4 book ai didi

google-admin-sdk - 检索 Google 用户照片

转载 作者:行者123 更新时间:2023-12-04 17:05:11 25 4
gpt4 key购买 nike

我能够检索 thumbnailPhotoUrl来自 google admin SDK 的 user.list api。但是,每当我尝试渲染图像时,Google 都会重定向到静态剪影图像。通过 API 检索的 URL 如下所示

https://plus.google.com/_/focus/photos/private/AIbEiAIA.... 

如前所述,这最终被重定向到:
https://ssl.gstatic.com/s2/profiles/images/silhouette200.png

但是,通过一些逆向工程,我可以通过将/u/1/添加到 URL 路径的开头来查看照片,如下所示:
https://plus.google.com/u/1/_/focus/photos/private/AIbEiAIA...

根据我的研究,/u/1 与多个谷歌帐户有关,所以恐怕我无法依赖这种方法。谁能帮我理解这里发生了什么?

最佳答案

根据我自己的经验,我发现如果 thumbnailPhotoUrl 在 URL 上具有私有(private)然后照片不公开,即在域外无法查看,也可能是用户尚未激活他们的 Google+ 个人资料,我相信无论如何都会公开他们的照片。

最好避免使用 thumbnailPhotoUrl 如果 URL 上有私有(private)路径。我认为使用 Users.Photo API 将照片检索为 Web 安全的 base64 数据更可靠。然后将其编码为内联 base64 CSS 图像。

这是我通常使用的代码片段:

    import com.google.common.io.BaseEncoding;
import com.google.api.services.admin.directory.model.User;
import com.google.api.services.admin.directory.model.UserPhoto;

public class PhotoUtils {

public void loadPhoto() {
// if the user have not signed up for Google+ yet then their thumbnail is private
String thumbnailUrl = user.getThumbnailPhotoUrl();
String photoData = "";
if((thumbnailUrl != null) && (thumbnailUrl.indexOf("private") > -1)) {

UserPhoto photo = getUserPhoto(user.getId());
if(photo != null) {
photoData = getBase64CssImage(photo.getPhotoData(), photo.getMimeType());
}
}

}

public static String getBase64CssImage(String urlSafeBase64Data, String mimeType) {
urlSafeBase64Data = new String(BaseEncoding.base64().encode(
BaseEncoding.base64Url().decode(urlSafeBase64Data)));
return "data:" + mimeType + ";base64," + urlSafeBase64Data;
}

public UserPhoto getUserPhoto(String userId) throws IOException {
UserPhoto photo = null;
try {
photo = this.getClient().users().photos().get(userId).execute();

} catch(GoogleJsonResponseException e) {
if(e.getMessage().indexOf(NOT_FOUND) == 0) {
log.warning("No photo is found for user: " + userId);

} else {
throw e;
}
}
return photo;
}
}

关于google-admin-sdk - 检索 Google 用户照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25467326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com