- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在一个网站上工作,客户要求提供允许使用 Google 和 Facebook 帐户注册/登录的选项。如何从用户的 Google 个人资料中提取电子邮件地址以存储在数据库中?
这是我的代码。问题是我没有完全获取用户配置文件。相反,我只收到用户名。
try
{
WebClient client = new WebClient();
var urlProfile = "https://www.googleapis.com/oauth2/v1/userinfo?access_token="
+ access_token;
string outputData = client.DownloadString(urlProfile);
GoogleUserOutputData serStatus =
JsonConvert.DeserializeObject<GoogleUserOutputData>(outputData);
if (serStatus != null)
{
return serStatus;
// You will get the user information here.
}
}
catch (Exception ex)
{
//catching the exception
}
return null;
最佳答案
这是一种在 JavaScript 中接收数据(电子邮件等)的方法。最后,它会显示带有数据的警报。 (您可以将此数据存储在数据库中。)这是一个带有 Google 按钮的完整工作示例。
<html>
<head>
<title>Demo: Getting an email address using the Google+ Sign-in button</title>
<!-- Include the API client and Google+ client. -->
<script src = "https://plus.google.com/js/client:platform.js" async defer></script>
</head>
<body>
<!-- Container with the Sign-In button. -->
<div id="gConnect" class="button">
<button class="g-signin"
data-scope="email"
data-clientid="Your_Client_ID"
data-callback="onSignInCallback"
data-theme="dark"
data-cookiepolicy="single_host_origin">
</button>
<!-- Textarea for outputting data -->
<div id="response" class="hide">
<textarea id="responseContainer" style="width:100%; height:150px"></textarea>
</div>
</div>
</body>
<script>
/**
* Handler for the signin callback triggered after the user selects an account.
*/
function onSignInCallback(resp) {
gapi.client.load('plus', 'v1', apiClientLoaded);
}
/**
* Sets up an API call after the Google API client loads.
*/
function apiClientLoaded() {
gapi.client.plus.people.get({userId: 'me'}).execute(handleEmailResponse);
}
/**
* Response callback for when the API client receives a response.
*
* @param resp The API response object with the user email and profile information.
*/
function handleEmailResponse(resp) {
var primaryEmail;
var name;
var gender;
for (var i=0; i < resp.emails.length; i++) {
if (resp.emails[i].type === 'account')
primaryEmail = resp.emails[i].value;
if (resp.displayName != null)
name = resp.displayName;
gender = resp.gender;
}
document.getElementById('responseContainer').value = 'Primary email: ' +
primaryEmail + '\n\nFull Response:\n' + JSON.stringify(resp);
ShowAlert("Email: "+primaryEmail +" "+"Name: "+ resp.displayName +" "+"Gender: "+gender);
}
</script>
</html>
有关更多信息和详细信息,您可以(应该)阅读此链接: Getting people and profile information
关于javascript - 从 Google 帐户中提取电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45756440/
我正在尝试从如下所示的变量中提取一些内容: v1 ","person 2 ") (该变量有数百个观察值) 我想最终创建第二个变量来提取他们的电子邮件以提供以下输出: v2 ","person 2 ")
当您添加 facebook 连接以允许 facebook 用户登录您的站点时,您可以取消用户名和电子邮件地址吗? 最佳答案 是的,您需要先提示他们“电子邮件”数据权限。 Facebook 也在很快改变
我们正在寻求建立一个专门用于商业/商业用途的新网站。我们只需要允许“企业”电子邮件地址注册。因此,使用 Gmail、Hotmail、Yahoo 等的用户无法使用这些电子邮件地址申请。 除了创建 gma
我想通过Identity内的Claim访问我的电子邮件地址 我尝试访问为: var email = User.Identity.GetClaimsByType("emailaddress").ToSt
我正在使用 Hammock 库和 C# 从以下帖子中的链接获取用户的基本配置文件和电子邮件地址 here . 我也关注了这些帖子 here和 here 然而,对于我来说,我无法获得 linkedin
我正在使用 Hammock 库和 C# 从以下帖子中的链接获取用户的基本配置文件和电子邮件地址 here . 我也关注了这些帖子 here和 here 然而,对于我来说,我无法获得 linkedin
我正在尝试制作一个应用程序,通过获取 json 编码数组来从 SQL 数据库获取数据。 它获取地址数据和其他类型的数据,然后将其传递给 Mapkit map View 元素和一些标签/ TextVie
当使用钥匙串(keychain)和证书助手从现有 CA 申请证书时,所有说明都说我应该单击“保存到磁盘”选项,并且不需要“CA 电子邮件地址”。 我看到的面板没有提供“保存到磁盘”选项,当我尝试在没有
我的问题不在于我无法将电子邮件保存到数据库中。任何人都可以做到。这是我的问题: 当用户在我的网站上创建帐户时,他们会获得 ID、用户、密码和电子邮件地址数据。对于密码,我对其进行哈希处理,这样如果有人
我想向非 ASCII 电子邮件地址发送电子邮件,但我不确定使用 JDK8 的推荐程序是什么。 我应该如何处理以下电子邮件地址? Dörte@example.com test@Sörensen.de D
我想阻止用户: 从第一个文本框复制粘贴到第二个 右键单击并使用上下文菜单将第一个文本框复制并粘贴到第二个文本框。 这是行不通的。 Confirm email page
我正在使用两个不同的 Git 存储库(即 github 和 stash),我想为每个存储库使用不同的电子邮件地址。我知道我可以使用 git config 但我不想每次创建新工作区时都必须记住这样做。所
类似于this question ,但不确定在这种情况下如何实现。 受信任的用户(不需要关心验证输入)正在将电子邮件地址键入/粘贴到文本字段中。在模糊事件中,我想查看文本并清理他输入的任何内容(通常是
我正在使用以下代码使用 VBA 发送电子邮件。但是,没有发送电子邮件......我认为这是由于 '.To = ' 代码行中有多个电子邮件地址。有没有办法调整代码以允许多个电子邮件地址? 我试过看 Ro
我正在尝试制作一个脚本,该脚本将在整个网页中搜索以@xyz.com 结尾的电子邮件地址。例如: $(document).ready(function() { $("body:contains(
我们正在使用Office 365,并且遇到了创建重复帐户的问题。这会导致在用户地址上添加数字(john.doe@c0mpany.onmicrosoft.com也将是john.doe5826@c0mpa
我的类型是用户:电子邮件和用户名。 电子邮件字段设置为字符串类型,并使用自定义分析器“exact_lower”: index.analysis.analyzer.exact_lower: type
这个问题已经有答案了: Delete a specific user from Firebase (6 个回答) 已关闭 3 年前。 我正在建立一个网站,其中某个“管理员”用户可以删除任何其他用户的帐
我已经完成 Facebook 登录,但我不知道如何获取电子邮件地址并以其他形式显示它 所以,这就是代码 private void nextActivity(Profile profile){
我有一个付费应用程序,安装后用户可以使用购买该应用程序的电子邮件地址进行注册。 我想知道这个电子邮件地址是否从Google Play购买了我的应用(验证),否则拒绝其注册。有什么办法(API)? 最佳
我是一名优秀的程序员,十分优秀!