谷歌加(获取图片的URL) [英] Google plus ( Get picture url )

查看:285
本文介绍了谷歌加(获取图片的URL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我坚持获取图片的URL从谷歌加响应的问题。

I am stuck with a problem for getting picture URL as a response from Google Plus.

下述正是我需要的。

{
 "id": "ID",
 "name": "NAME",
 "given_name": "GiVEN NAME",
 "family_name": "FAMILY_NAME",
 "link": "https://plus.google.com/ID",
 "picture": "https://PHOTO.jpg",
 "gender": "GENDER",
 "locale": "LOCALE"
}

直到一次,我为了在用下述获得相同。请看看..

Till time I am using undermentioned in order to get same. please have a look ..

在onConnected()使用下述;

Using undermentioned in onConnected();

try {
                 URL url = new URL("https://www.googleapis.com/oauth2/v1/userinfo");
                  //get Access Token with Scopes.PLUS_PROFILE
                  String sAccessToken;
                sAccessToken = GoogleAuthUtil.getToken(MainActivity.this,
                                          mPlusClient.getAccountName() + "",
                                          "oauth2:" + Scopes.PLUS_PROFILE
                                          + " https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email");

                   HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
                      urlConnection.setRequestProperty("Authorization", "Bearer "
                              + sAccessToken);
                      BufferedReader r = new BufferedReader(new InputStreamReader(
                              urlConnection.getInputStream(), "UTF-8"));
                      StringBuilder total = new StringBuilder();
                      String line;
                      while ((line = r.readLine()) != null) {
                          total.append(line);
                      }
                      line = total.toString();
                      System.out.println("::::::::::::::::::::::::" + line);
            } catch (UserRecoverableAuthException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Intent recover = e.getIntent();
                startActivityForResult(recover, REQUEST_AUTHORIZATION);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (GoogleAuthException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

上述输出::

{ "id": "106193796000956371669", "email": "vivek@xyz.com", "verified_email": true, "name": "Vivek Singh", "given_name": "Vivek", "family_name": "Singh", "link": "https://plus.google.com/10619379600095669", "gender": "male", "locale": "en", "hd": "xyz.com"}

请让我们知道我错过了什么。
任何建议可能是对我有帮助的。

Please let know about what I am missing. Any suggestion might be helpful for me.

谢谢!

推荐答案

您可以进行查询,直接拿到资料图片,如果你知道用户,您可以从您的code获取的ID。

You can make a query to get the profile picture directly if you know the ID of the user, which you can get from your code.

只要一个电话

https://plus.google.com/s2/photos/profile/" + user.getGooglePlusId() + "?sz=100

其中, getGooglePlusId() 是一个用户定义的函数,它返回用户的ID和
SZ 指定图像的大小返回。

where getGooglePlusId() is a user-defined function which returns the ID of the user and sz specifies the size of the image returned.

编辑:

这是过时的,现在(2015年12月)
您应该使用
https://www.googleapis.com/plus/v1/people/ {} GOOGLE_USER_ID?关键= {YOUR_API_KEY}
其中:

This is outdated for now (december 2015) You should use https://www.googleapis.com/plus/v1/people/{GOOGLE_USER_ID}?key={YOUR_API_KEY} where:

GOOGLE_USER_ID - 在谷歌加上用户的ID

GOOGLE_USER_ID - ID of the user in Google Plus

YOUR_API_KEY - Android的API密钥(你可以阅读如何得到它的这里

YOUR_API_KEY - Android API key (You can read how to get it here)

有关此请求的响应将返回JSON,其中包含一个形象领域。这实际上是用户的个人资料图片。您可以尝试在这里这进行试验。

The response for this request would return JSON, which contains an "image" field. This is actually user profile image. You can try to experiment with this here.

顺便说一下,存在着的 10000 的每天访问此API的限制。在您的谷歌API控制台,您可以要求谷歌更多的配额,但我不知道它是如何工作的。

By the way, there is a limit of 10000 accesses per day to this API. In your google api console you can ask Google for more quota, but I don't know how it works exactly.

这篇关于谷歌加(获取图片的URL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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