简体   繁体   English

哪些正确的Google+作用域变量可以获取电子邮件地址并发布?

[英]Which are the correct Google+ scope variables to get email address and to post?

I'm using spring-social-google (built from the git repo) to allow people to sign into my Spring MVC application (I already have facebook, twitter and linedin working). 我正在使用spring-social-google(从git repo构建)来允许人们登录到我的Spring MVC应用程序(我已经在使用facebook,twitter和linedin)。 The form below allows me to authenticate, but an email address is not returned and posting to the Google+ timeline is prohibited: 以下表格允许我进行身份验证,但不会返回电子邮件地址,并且禁止发布到Google+时间轴:

<form action="<c:url value="/register/social/${providerId}" />" method="POST" id ="${providerId}Form" name = "${providerId}Form">
    <button type="submit"><img src="<c:url value='/resources/${providerId}/sign-in-with-${providerId}.png'/>" border="0"/></button>
    <input type="hidden" name="scope" value="https://www.googleapis.com/auth/plus.profile.emails.read" />                   
</form>

I think the issue is that I don't have the correct scope variables. 我认为问题是我没有正确的范围变量。 I've tried some of the combinations here https://developers.google.com/+/api/oauth but I get told that the scope variables are all wrong. 我在这里https://developers.google.com/+/api/oauth尝试了一些组合,但是我被告知范围变量都是错误的。 Which ones do I need? 我需要哪些?

This is the code for I'm using to get the email address: 这是我用来获取电子邮件地址的代码:

public final class LoginConnectionSignUp implements ConnectionSignUp 
{   
    public String execute(Connection<?> connection) 
    {
        final UserProfile up = connection.fetchUserProfile();
        final String email = up.getEmail();
        // ...
    }

}

There are a couple of issues here: 这里有几个问题:

Posting to the Google+ Stream isn't supported by Google's API at this time. 目前Google的API不支持发布到Google+流。 The package appears to let you create "app activity moments", which are stored on the user's profile... but these aren't posts to the stream. 该软件包似乎可以让您创建“应用活动记录”,这些记录存储在用户的个人资料中...但这些不是发布到信息流中。 In order to generate an app activity, you need to include the https://www.googleapis.com/auth/plus.login scope. 为了生成应用活动,您需要包括https://www.googleapis.com/auth/plus.login范围。

Additionally, you can include either the email scope or the https://www.googleapis.com/auth/plus.profile.emails.read scope. 此外,您可以包括email范围或https://www.googleapis.com/auth/plus.profile.emails.read范围。 With these scopes, you should be able to get the email address as part of the call to 通过这些作用域,您应该能够将电子邮件地址作为对的调用的一部分

Person person = google.plusOperations().getPerson("me");

So your input tag should probably look something like 所以您的输入标签应该看起来像

<input type="hidden" name="scope" value="https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.profile.emails.read" />                   

(note the space between the two scopes to use). (请注意要使用的两个示波器之间的空间)。

Important note : The documentation talks about getting the email via a call such as 重要说明 :文档讨论如何通过诸如

GoogleUserInfo userInfo = google.userOperations().getUserInfo();

while this may work for now, it is deprecated and scheduled to be removed in September. 虽然目前暂时可以使用,但已弃用并计划在9月将其删除。 The userinfo scopes are also set to be deprectaed at this time. userinfo范围也被设置为此时不被使用。 Don't use this method or these scopes. 不要使用此方法或这些范围。 (And contact the author to tell them to deprecate it.) (并联系作者以使其不赞成使用。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM