你不必做任何事情。我在应用引擎上有一个联合登录应用,我最近添加了一个使用云终端的Android应用。你不需要做任何特别的事情,只需要在你的函数中添加一个User参数。在用户对象中,您将找到您必须授权才能访问数据的用户电子邮件。
@Api(name = "my_api",
version = "v1",
scopes = {"https://www.googleapis.com/auth/userinfo.email"},
clientIds = {Constants.AUTH_CLIENT,
Constants.AUTH_CLIENT_APIEXPLORER})
public class MyEndpoint {
@ApiMethod(name = "fistEndpoint")
public ResponseObject fistEndpoint(User user) throws OAuthRequestException {
if (user == null) {
throw new OAuthRequestException("Access denied!");
}
String email = user.getEmail();
//Authorize the request here
//make the ResponseObject and return it
}
}
后您创建的端点访问: https://your-app.appspot.com/_ah/api/explorer并测试它
更新:上面的例子仅限于谷歌账号。如果你想要一个不同类型的账户,你可以看看这篇文章: Custom Authentication for Google Cloud Endpoints (instead of OAuth2)