无法在Android中使用google apis获取用户个人资料 [英] Unable to get User Profile from google using google apis in android

查看:159
本文介绍了无法在Android中使用google apis获取用户个人资料的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Google集成到我的Android应用程序中。我使用oauth来检索请求令牌,访问令牌。我想要用户的名字,姓氏,屏幕名称,电子邮件。这是我想要做的,

I am trying to integrate google in my android app. I am using oauth for retriving request token, access token. I want User's FirstName, LastName, ScreenName, Email. Here is what I am trying to do,

public static final String CLIENT_ID = "XXXX";
public static final String CLIENT_SECRET = "XXXX";
private static final String SCOPE = "https://www.googleapis.com/auth/userinfo.profile";
public static final String REQUEST_TOKEN_URL = "https://www.google.com/accounts/OAuthGetRequestToken";
public static final String ACCESS_TOKEN_URL = "https://www.google.com/accounts/OAuthGetAccessToken";
public static final String AUTHORIZE_URL = "https://www.google.com/accounts/OAuthAuthorizeToken";

我连接到Google,要求授予个人资料信息的访问权限。用户授予访问权限,回到我的应用程序。现在我正在尝试这样做,

I get connected to google asking to grant access for profile information. User grants the access, comes back to my application. Now I am trying to do this,

DefaultHttpClient httpClient = new DefaultHttpClient();
String strUrl = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json";
HttpPost request = new HttpPost(strUrl);

来获取用户的个人资料。但作为回应,我只得到

to get the user's profile. But In response I get only


{

{



<没有数据。我尝试了很多以获取用户配置文件。 Plz告诉我我做错了什么。任何链接,示例代码将不胜感激。提前致谢。

No data. I tried a lot to get the user profile. Plz do tell me where I am doing wrong. Any links, sample code will be appreciated. Thanks in advance.

推荐答案

尝试使用HttpGet而不是HttpPost。该请求需要是资源的GET请求,而不是POST请求。

Try using an HttpGet instead of HttpPost. The request needs to be a GET request for the resource, not a POST request.

这篇关于无法在Android中使用google apis获取用户个人资料的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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