我正在开发一个使用Google API从Google日历获取数据的网站,
因此,我从Google文档中获取了测试代码并对其进行了自定义。
当我在本地调试它时,一切正常,它打开了一个新标签,并要求像其应有的那样访问Google帐户。
这是我用于获取响应令牌的方法:
private static UserCredential GetCredential()
{
UserCredential credential;
var path = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "App_Data/credentials.json");
using (var stream =
new FileStream(path, FileMode.Open, FileAccess.Read))
{
string credPath = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, ".credentials/calendar-access.json");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
return credential;
}
我的问题出在服务器上,当我第一次尝试从Google获取数据时,页面进入了无限循环。
恐怕该标签可能会从Google帐户中获取访问权限,并且该标签正在服务器上打开,并且为什么它会无限加载。
所以我的问题是,
首先,如果可能的话,如果可以的话,我该如何解决?
其次,有更好的方法吗?
答案 0 :(得分:1)
我为此找到了一种解决方案,并进行了多客户端身份验证,请在此处查看我的帖子:
答案 1 :(得分:0)