无法在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
{
{
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.