我正在尝试获取用户电子邮件,这是我在应用程序中通过Youtube执行Oauth2时经常使用的登录电子邮件。代码如下所示:
YouTube client = new YouTube.Builder(GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory
.getDefaultInstance(), credential)
.setApplicationName("app_name").build();
YouTube.Channels.List channelListByIdRequest = client.channels().list("snippet,contentDetails,statistics");
channelListByIdRequest.setMine(true);
ChannelListResponse channelListResponse = channelListByIdRequest.execute();
这里我拉出了channel api,根据文档,它有点类似于v3中的user api。然而,无论是在Channel中还是在任何其他API中,我都找不到如何获取我登录时使用的电子邮件。如何访问这些信息?
发布于 2019-01-04 16:11:55
我做了一些研究,不幸的是,确实没有可能获取电子邮件。据我所知,这与Youtube及其数据API的概念背道而驰--它涉及多个渠道,其中多个渠道可以与一封电子邮件相关联。参考:https://developers.google.com/youtube/v3/getting-started
然而,你可以使用Google + API作用域和Youtube作用域来获取用户信息(但我们需要考虑到这些信息将在2019年3月7日之前被丢弃)
GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), clientSecrets,
Arrays.asList(YouTubeScopes.YOUTUBE_FORCE_SSL, PlusScopes.PLUS_ME, PlusScopes.USERINFO_EMAIL))
.setAccessType("offline").setApprovalPrompt("force").build();
我们将被提示在Oauth窗口中选择电子邮件和渠道,并将能够获取信息。
https://stackoverflow.com/questions/48631420
复制相似问题