【发布时间】:2014-01-27 11:44:14
【问题描述】:
我在获取图片 URL 作为 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"
}
直到我使用下面提到的为了得到相同。请看看..
在 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"}
请告诉我我错过了什么。 任何建议都可能对我有所帮助。
谢谢!
【问题讨论】:
-
您能否展示您最终是如何使用 Swayam 的答案从 Google 获得图像的?这真的会帮助像我这样正在寻找答案的其他人。谢谢
-
@OjonugwaOchalifu .. 请检查我的答案。谢谢。
标签: android google-plus