2

经过漫长的学习曲线,我设法使用 Google API 客户端库成功获取了用户的个人资料信息。

除了姓名和电子邮件地址,当用户登录我的网络应用程序时,我可以获取他们的个人资料图片。

麻烦的是,图片在尺寸和字节上都很大。此类图片的 url 如下所示:

https://lh4.googleusercontent.com/-rdhxDPbmVhg/AAAAAAAAAAI/AAAAAAAAAJQ/6Dsr5psyQPs/photo.jpg

(是的,那是我在珊瑚城堡)。

有没有办法获得缩略图或图标大小的个人资料图片,就像我在 Google 搜索结果中在作者旁边看到的那种?我注意到这些不是 URL,而是数据对象,所以我可能必须在 php 中做一些事情来将其呈现为图像?

在 Google 搜索的结果列表中,作者的图像信息示例如下所示:

data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/4QBgRXhpZgAASUkqAAgAAAACADEBAgAHAAAAJgAAAGmHBAABAAAALgAAAAAAAABQaWNhc2EAAAMAAJAHAAQAAAAwMjIwAqAEAAEAAAAsAAAAA6AEAAEAAAAsAAAAAAAAAP/bAIQAAwICAwICAwMDAwQDAwQFCAUFBAQFCgcHBggMCgwMCwoLCw0OEhANDhEOCwsVFhAUExQVFRcMDxcUFhQTFxQVEAEDBAQGBQYJBgYKEg0LDhIVEBAQFBEQEw8UDhUQFRAQDxAQDxEQFA8NEA8QDQ0QDw0ODBAQEAwMDBAPDw8MDA8P/8AAEQgALAAsAwERAAIRAQMRAf/EABkAAAMBAQEAAAAAAAAAAAAAAAYHCAkFAf/EADIQAAEDAwIEBAQFBQAAAAAAAAECAwQFBhEAIQcSMUETIlGBCCNxkRQyYZLBFTNSocL/xAAaAQACAwEBAAAAAAAAAAAAAAAEBQIDBgcB/8QALxEAAQMDAQQJBAMAAAAAAAAAAQACAwQRITEFEkFREyJhcYGRobHBFCPR8EJi4f/aAAwDAQACEQMRAD8AzPjsKlQ6iAQCGEn7vtJ/61DSytOiZPDHgA5xImRk0tmS/F5EeNIkHw0BePOBjGwPfOdKKiv6G4da/Ls4J3Q7MdUAG2Oaf1b+A56ZbzjdM/pr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kp1TzcyFEkrRyq+alSAopwfXYHOq4WDfF9PhC1MpDHEageqkHjtw5pF30mFUKk6+mWuap1ciK2hLrylIVzKcUUkqz5M9D5RvnpoKd5jkeOAGnZjRY+Zom3OBcde08SuFaPw8WbIowVJo635AedQtanXVZKVkdlbYAG2iTVdJ1o7gcsXHevZaD6d5iebkcQDY4vi6T9lXbSLMqjsipBS47sZxrwhjzqJGM5I21HonSRSMGrhZDTlolheP4u3jz0Ix25RVwxvo0mh1BFNTLqEJh1YlPK5PD5MoUhQwonPXm9OZPXzECu2dI4Em2OX++KdDa0W8N0HPO3Pv1tYKruFXFK34sSP4clyRKcSUiKwlSnE+g5cbe+NK/p36OTZ1ZHa7U97Itx7iO3VEz21Q4LzS2VNEBXgNrSUkq7FZBOB/GmFLROneAzQan4HaktXXiBhc/U6D5Uo8ebiiUC559pNxXJEmLVH0pbV2ZQvyEHPXBT+7Vs8JZJIB3fvglVLXQEMdKSLEE4S0l1enNTJJRUqpHccdWtxqI4EISoqONt9+Xl++NRgiYGDfAv4/Bzy8AmNbtkSzF0Uh3MW6o0t/YX1ufFJywYcSoypQnxGZ7CUgmPIBKF9Tg4IPUDvphNgsAxql8ZvFKT2e6aPCWDBlcK1uNwI0QTXJ7jjbCMJHIlsAAEnY4Gc56DGNH5ZTyPBz+lLo7PmjYRgo94I1F2Bbi6k0EfjGo5KHFJzg6QTCxstNHkAquaNKVZFfuybTAA5CoUqQEOkqS8tnkU2XBkc2+T7n110EsbBT7rBhuQubzPdLIXuOTqoNZqcq4K1Xq9UX1zKq86ouSHdypR86j9SpRz7emsHK4m1+OSiHYACXNQqDzUlRSrdz5iie6judXNaCEaBhf/9k=

如果需要,我欢迎帮助我澄清问题。

4

2 回答 2

7

您可以通过将参数附加?sz=(size in pixels)到您获得的 URL 来调整图像的大小。

例子

https://lh4.googleusercontent.com/-rdhxDPbmVhg/
AAAAAAAAAAI/AAAAAAAAAJQ/6Dsr5psyQPs/photo.jpg?sz=50

将显示为 示例个人资料图片

您使用什么方法来检索用户信息?

为经过身份验证的用户调用的 Google+ API的people.get 方法userId=me将已经返回一个 URL,该 URL 带有一个?sz=50添加image.url到响应字段中的参数。

于 2013-06-11T14:39:38.393 回答
2

只需将大小参数传递给 URL?sz=200

它会变成类似https://lh3.googleusercontent.com/--sahsjak8sjdbs5kNk/AAAAdshjgdshdgAAI/AAAAsdhsHY/knQ6LGqP1Yk/photo.jpg?sz=200

你很高兴去!

于 2016-09-23T06:31:21.977 回答