我是 Alexa 技能开发的新手,我正在尝试开发一项 Alexa 通过我的电子邮件回复的技能。
我正在开发 Java 技能,并且我刚刚能够通过以下方式获取用户会话 ID:
getSession().getUser().getUserId()
Getting amzn1.ask.account.{id}
作为解决方案
问题是需要获取用户电子邮件(例如:[电子邮件受保护] /cdn-cgi/l/email-protection)
有什么方法可以做到吗?
感谢帮助!
As 普里亚姆·古普塔 https://stackoverflow.com/users/5361054/priyam-gupta说,这是解决的api.amazon.com/user/profile?access_token= http://api.amazon.com/user/profile?access_token=我用来解决这个问题的代码是:
String accessToken = requestEnvelope.getSession().getUser().getAccessToken();
String url = "https://api.amazon.com/user/profile?access_token=" + accessToken;
JSONObject json = readJsonFromUrl(url);
String email = json.getString("email");
String name = json.getString("name");
使用 JSON 方法:
private static String readAll(Reader rd) throws IOException {
StringBuilder sb = new StringBuilder();
int cp;
while ((cp = rd.read()) != -1) {
sb.append((char) cp);
}
return sb.toString();
}
public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException {
InputStream is = new URL(url).openStream();
try {
BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
String jsonText = readAll(rd);
JSONObject json = new JSONObject(jsonText);
return json;
} finally {
is.close();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)