因此我遵循http://www.daimto.com/的幾個示例,即http://www.daimto.com/webmaster-tools-api-with-c/。經過漫長的一夜之後,我才得以開始工作。我這樣做的方式是通過簡單地移除GoogleWebAuthorizationBroker中的新FileDataStore每次都會產生一個新端口
new FileDataStore("Daimto.GoogleWebMasters.Auth.Store")
的代碼更改爲:
UserCredential credential = GoogleWebAuthorizationBroker(new ClientSecrets
{ ClientId = clientId, ClientSecret = clientSecret }
, scopes
, userName
, CancellationToken.None
, null).Result; // <-- notice null here
那麼,真的有必要的數據存儲?當我添加它時,我的IIS每次刷新都會生成一個新的端口號,這使得無法在谷歌中授權url重定向。 btw,我嘗試了目錄的物理完整路徑,但結果相同。
在GoogleApis.Auth.DotNet4/OAuth2/LocalServerCodeReceiver中。cs,端口在GetRandomUnusedPort()中隨機分配() –
謝謝DalmTo,我讀了你的建議,並嘗試了一個自定義的DataStore。這並沒有改變隨機端口問題。此外,我發現當我發佈解決方案時,它會引發錯誤。所有這些問題都可以通過避免使用GoogleWebAuthorizationBroker解決,並使用我在已添加的答案中鏈接的解決方案。 –