Google用户照片API-未经认证即可获取公共用户照片 [英] Google Users photos API - get the public user photo without authenticating

查看:109
本文介绍了Google用户照片API-未经认证即可获取公共用户照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我们使用Google Plus API来获取用户的公开照片. 我们需要的只是获取照片的用户ID(如此处所述 ).

Up until now, we used the Google Plus API to get a user's public photo. All we needed was the user id to get the photo (as described here).

现在不建议使用此API和Picasa API,我发现的唯一替代方法是使用Users.photos API(如此处所述).

Now that this and the Picasa APIs are being deprecated, the only alternative I found is using the Users.photos API (as described here).

正如您在说明中所看到的,此API需要授权,尽管已弃用的API不需要授权,而且我希望获得的照片是公开的.并非我们所有的用户都使用Google登录,但是我希望能够向所有人展示使用Google登录的用户的公开照片.现在有什么办法吗?

As you can see in the description, this API requires authorization, although the deprecated APIs did not, and the photo I wish to get is public. Not all of our users login with Google, but I want to be able to show everyone the public photos of the users which did login with Google. Is there any way to do this now?

推荐答案

您可以使用 people.get方法,仅使用用户ID即可获取所需的信息.尽管您可以在没有用户令牌的情况下获取公共信息,但您需要API密钥.如果信息不是公开的,您也将无法获得.

You can use the people.get method of the Google People API to get the information you need with just the user ID. While you can get public information without the user's token, you will need an API key. You also won't be able to get the information if it isn't public.

您需要准确要求您想要的字段. 名称"和照片"字段可能是对您最重要的字段,但还有其他可用的字段.您将获得一个可能值的数组,每个值指示其来源.您可能会希望使用"PROFILE"的源类型,但是您当然可以评估其他类型.

You need to request exactly which fields you want. The "names" and "photos" fields will probably be the ones most important to you, but there are others available. You'll get an array of possible values, each indicating their source. You will probably want the source type of "PROFILE", but you can certainly evaluate others.

因此,如果您发出的请求是

So if you issued a request with

GET https://people.googleapis.com/v1/people/101852559274654726533?personFields=names%2Cphotos&key={YOUR_API_KEY}

您将要求提供我的公开个人资料.您将获得类似

You'll be asking for my public profile. You'll get back a response something like

{
 "resourceName": "people/101852559274654726533",
 "etag": "%EgYBAj0DNy4aDAECAwQFBgcICQoLDA==",
 "names": [
  {
   "metadata": {
    "primary": true,
    "verified": true,
    "source": {
     "type": "PROFILE",
     "id": "101852559274654726533"
    }
   },
   "displayName": "Allen "Prisoner" Firstenberg",
   "familyName": "Firstenberg",
   "givenName": "Allen",
   "displayNameLastFirst": "Firstenberg, Allen"
  }
 ],
 "photos": [
  {
   "metadata": {
    "primary": true,
    "source": {
     "type": "PROFILE",
     "id": "101852559274654726533"
    }
   },
   "url": "https://lh5.googleusercontent.com/-RDndFau_En4/AAAAAAAAAAI/AAAAAAAB8CY/sTL9kJMmIgk/s100/photo.jpg"
  }
 ]
}

这篇关于Google用户照片API-未经认证即可获取公共用户照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆