# 在移动应用中同时使用 API 和 WebView，能否防止重复登录？

**URL:** <https://meta.discourse.org/t/using-both-api-and-webview-in-mobile-app-can-you-prevent-logging-in-twice/146189>\
**Category:** Development\
**Created:** [2020年三月30日 19:38 UTC](https://meta.discourse.org/t/using-both-api-and-webview-in-mobile-app-can-you-prevent-logging-in-twice/146189 "2020-03-30T19:38:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![xceph](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/xceph/32/174216_2.png) [@xceph](https://meta.discourse.org/u/xceph)\
**Post date:** [2020年三月30日 19:38 UTC](https://meta.discourse.org/t/using-both-api-and-webview-in-mobile-app-can-you-prevent-logging-in-twice/146189/1 "2020-03-30T19:38:48Z")

</div>

我目前正在努力将 Discourse 集成到现有的 iOS 和 Android 应用中。原计划是利用现有的 Discourse 网站进行浏览，但使用 API 来创建帖子，因为我有许多与应用相关的字段，希望在发帖时预先填充。我对 Web 开发经验不多，所以这对我来说大多是全新的，只能边做边学。

我能够通过 API 登录并生成 API 密钥。我原本的想法（现在回想起来觉得完全不合理）是，使用这种方法可以同时与 WebView 共享会话，使其自动保持登录状态。

显然事实并非如此。我似乎能够完成所有预期的操作，但我需要登录两次：一次通过 API，一次通过 WebView。有没有办法简化这一过程，实现单次登录即可同时验证 WebView 并允许 API 访问？
