无法获取用户配置文件谷歌使用谷歌apis android
问题描述:
我想在我的Android应用程序中集成谷歌。我使用oauth来检索请求令牌,访问令牌。我想要用户的名字,姓氏,屏幕名称,电子邮件。这就是我要做的,无法获取用户配置文件谷歌使用谷歌apis android
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要求授予的配置文件信息的访问。用户授予访问权限,回到我的应用程序。现在我试图做到这一点,
DefaultHttpClient httpClient = new DefaultHttpClient();
String strUrl = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json";
HttpPost request = new HttpPost(strUrl);
得到用户的配置文件。但作为回应,我只得到
{
无数据。我尝试了很多以获取用户配置文件。 Plz告诉我我做错了什么。任何链接,示例代码将不胜感激。提前致谢。
答
尝试使用HttpGet而不是HttpPost。该请求需要是资源的GET请求,而不是POST请求。