Hello!
I am trying to get Google User Email using Email Display Scope
described here: http://sites.google.com/site/oauthgoog/Home/emaildisplayscope
The oauthParameters contain valid access_token and
access_token_secret. Using these tokens I can access picasa albums and
user's gmail inbox. I have also authorized the token key for email
display scope https://www.googleapis.com/userinfo/email.
My problem is when I call the function below I get an error BAD
REQUEST. I tired OAuthUtil.encode() parameters twice. Does not help.
Please advise me what is the problem with request?
public String getCurrentGmailUserName(GoogleOAuthParameters
oauthParameters) {
String returnValue = null;
try {
String oauth_timestamp = OAuthUtil.getTimestamp();
String oauth_nonce = OAuthUtil.getTimestamp();
String oauth_token = oauthParameters.getOAuthToken();
String oauth_signature_method = "HMAC-SHA1";
String signature = null;
String oauth_consumer_key = "_here_is_my_consumer_key";
Map<String, String> params = new HashMap();
params.put("oauth_consumer_key",
OAuthUtil.encode(oauth_consumer_key));
params.put("oauth_nonce", OAuthUtil.encode(oauth_nonce));
params.put("oauth_signature_method",
OAuthUtil.encode(oauth_signature_method));
params.put("oauth_timestamp",
OAuthUtil.encode(oauth_timestamp));
params.put("oauth_token", OAuthUtil.encode(oauth_token));
params.put("oauth_version", OAuthUtil.encode("1.0"));
String signatureBase =
OAuthUtil.getSignatureBaseString("https://www.googleapis.com/userinfo/
email", "GET", params);
signature = computeHmac(signatureBase,
Commons.CONSUMER_SECRET);
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod("https://
www.googleapis.com/userinfo/email");
method.addRequestHeader("Host:", "www.googleapis.com");
method.addRequestHeader("Accept:", "*/*");
method.addRequestHeader("Content-Type:", "application/atom
+xml");
StringBuilder authorization = new StringBuilder();
authorization.append("OAuth ");
authorization.append("oauth_token=\"" +
OAuthUtil.encode(oauth_token) + "\",");
authorization.append("oauth_signature_method=\"" +
oauth_signature_method + "\",");
authorization.append("oauth_signature=\"" +
OAuthUtil.encode(signature) + "\",");
authorization.append("oauth_consumer_key=\"" +
OAuthUtil.encode(oauth_consumer_key) + "\",");
authorization.append("oauth_timestamp=\"" +
OAuthUtil.encode(oauth_timestamp) +"\",");
authorization.append("oauth_nonce=\"" +
OAuthUtil.encode(oauth_nonce)+"\",");
authorization.append("oauth_version=\""+
OAuthUtil.encode("1.0")+"\"");
method.addRequestHeader("Authorization:",
OAuthUtil.encode(authorization.toString()));
// Execute the method.
int statusCode = client.executeMethod(method);
System.out.println(statusCode);
// read response body
returnValue = method.getResponseBodyAsString();
System.out.println(returnValue);
} catch (Exception ex) {
ex.printStackTrace();
}
return returnValue;
}
--
You received this message because you are subscribed to the Google Groups
"OAuth" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/oauth?hl=en.