【发布时间】:2017-12-21 12:22:16
【问题描述】:
我已经开始使用 GMail API,它在我的本地机器上运行良好;它将打开 Google 权限页面,我可以选择我的帐户。然后它会存储返回的 json 令牌,并且只会再次询问该令牌是否被移除。
当我发布到服务器时,OAUTH 页面永远不会显示,并且应用程序似乎因“线程被中止”异常而超时。
我的代码;
try
{
using (var stream = new FileStream(HttpContext.Current.Server.MapPath("~/credentials/client_id.json"), FileMode.Open, FileAccess.Read))
{
string credPath = HttpContext.Current.Server.MapPath("~/credentials/gmail_readonly_token.json");
_credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
db.writeLog("INFO", "Gmail Credentials Saved","Credential file saved to: " + credPath);
}
// Create Gmail API service.
service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = _credential,
});
}
catch (Exception e)
{
db.writeLog("Error", "Failure when creating Gmail class", e.Message, null, _username, null);
}
我需要在“client_id.json”(正式为 client_secret.json)文件中进行更改吗?我唯一改变的是redirect_uris 行。
欢迎提出任何其他建议,我能找到的唯一其他类似问题是here,但没有答案。
谢谢,
丹尼。
【问题讨论】:
标签: json oauth token gmail-api