我正在使用我自己的个人Google帐户玩Google的OAuth 2.0 Playground,但我似乎无法使用游乐场恢复我的Gmail地址.
我使用的范围是:
email profile https://www.googleapis.com/auth/plus.login
Run Code Online (Sandbox Code Playgroud)
但是当我调用API时:
https://www.googleapis.com/oauth2/v2/userinfo
Run Code Online (Sandbox Code Playgroud)
我得到有关用户的各种信息,如姓氏,名字,性别,图片等,但它不会返回用户的电子邮件.
如何检索用户的电子邮件地址?我是否有错误的范围或我是否使用了错误的API?我觉得这应该很简单,但我确实试图解决这个问题几个小时,我找不到一直提供用户电子邮件地址的API和范围组合.
我正在尝试为生产设置Django服务器.在我的浏览器中,如果我输入与我的服务器对应的IP地址,我会得到默认的Apache页面"它的工作原理!" 而不是与Django相关的页面.
我修改了httpd.conf以包含该行:
WSGIScriptAlias / /var/the-1/django/The1/apache/django.wsgi
Run Code Online (Sandbox Code Playgroud)
我创建了实际文件django.wsgi,它看起来像:
import os
import sys
path = '/var/the-1/django/The1'
if path not in sys.path:
sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'The1.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Run Code Online (Sandbox Code Playgroud)
但是当我重新启动服务器时,我收到错误:
AH00526: Syntax error on line 506 of /usr/local/apache2/conf/httpd.conf:
Invalid command 'WSGIScriptAlias', perhaps misspelled or defined by a module not included in the server configuration
Run Code Online (Sandbox Code Playgroud)
当我尝试使用以下命令重启Apache:
/usr/local/apache2/bin/apachectl -k restart
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用命令:
sudo service apache2 restart
Run Code Online (Sandbox Code Playgroud)
我没有收到错误(虽然我认为他们并没有真正做同样的事情).
如果我运行apache2ctl -M,则会出现以下两行(以及其他行):
alias_module (shared)
wsgi_module (shared)
Run Code Online (Sandbox Code Playgroud)
所以我相信这些模块运行正常.
我已经尝试完全卸载并重新安装libapache2-mod-wsgi.我正在处理的服务器是运行Raspbian的Raspberry Pi.这是我第一次设置服务器,所以我对Apache知之甚少或者如何设置Django.
编辑:下面是我的httpd.conf文件(请注意,因为实际文件太长,我删除了所有注释):
ServerRoot "/usr/local/apache2"
Listen 80
LoadModule authn_file_module …Run Code Online (Sandbox Code Playgroud) 据我所知,gson不会自动将java.util.Date对象序列化和反序列化为ISO字符串,如"yyyy-MM-ddTHH:mm:ssZ"或例如"2014-04-15T18:22:00-05" :00" .因此,为了让我在我的客户端(使用Retrofit和gson)和服务器之间正确地交换日期,我需要将DateFormat指定为gson.这就是我所做的:
// code defining the creation of a RestAdapter
// ...
new GsonBuilder()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
.create()
Run Code Online (Sandbox Code Playgroud)
添加.setDateFormat行足以让gson将时间戳字符串正确反序列化为Date对象.但是,它没有将Date对象序列化为时间戳字符串.所以我假设我必须像这样创建一个自定义序列化器:
// code defining the creation of a RestAdapter
// ...
new GsonBuilder()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
.registerTypeAdapter(Date.class, new DateSerializer())
.create()
Run Code Online (Sandbox Code Playgroud)
和DateSerializer类:
class DateSerializer implements JsonSerializer<Date> {
@Override
public JsonElement serialize(Date arg0, Type arg1, JsonSerializationContext arg2) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US);
return new JsonPrimitive(df.format(arg0));
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,序列化函数被忽略了.相反,gson将日期格式化为字符串,如"Tues Mar 15 18:22:00 EST 2014".所以为了测试,我尝试用以下代码替换serialize函数:
public JsonElement serialize(Date arg0, Type arg1, JsonSerializationContext arg2) {
throw new RuntimeException("Serialize …Run Code Online (Sandbox Code Playgroud)