[解決済み] 認証要求が予期しない結果を返した:404
2022-02-27 18:33:14
質問
例外の詳細 Google.GData.Client.GDataRequestException: 認証リクエストの実行により、予期しない結果が返されました: 404
以下は私のコードです。
protected void Button1_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.Tables.Add("GmailContacts");
ds.Tables[0].Columns.Add("EmailID");
RequestSettings rs = new RequestSettings("Gmail", txtUserName.Value, txtPassword.Value);
rs.AutoPaging = true;
ContactsRequest cr = new ContactsRequest(rs);
Feed<Contact> feed = cr.GetContacts();
foreach (Contact contact in feed.Entries)
{
foreach (Email email in contact.Emails)
{
DataRow dr = ds.Tables[0].NewRow();
dr["EmailID"] = email.Address.ToString();
ds.Tables[0].Rows.Add(dr);
}
}
GridView1.DataSource = ds;
GridView1.DataBind();
}
解決方法は?
私自身の解決策を確認する
ステップ
- 次のページに移動します。 https://console.developers.google.com/project をクリックし、プロジェクトを作成します。
- プロジェクトを選択し、左上のメニューからAPI & authを選択します。
- クレデンシャルを選択
- Create new Client ID」ボタンでOAuthを作成します(アプリケーションの種類 - Installed Aplication.
- 製品名フィールドを埋める
- 保存
これで、ネイティブアプリケーション用のクライアントIDが取得できました。 クライアントID。 クライアントの秘密 リダイレクトURI
NuGetからGoogle.Apis.Authをインストールする。
コード
string clientId = null; // https://console.developers.google.com/project/xxx
string clientSecret = null; // https://console.developers.google.com/project/xxx
string accessCode = null; // You will get this code after GetAccessToken method
string redirectUri = null; // https://console.developers.google.com/project/xxx
string applicationName = null; // https://console.developers.google.com/project/xxx
// Scopes https://support.google.com/a/answer/162106?hl=en
string scopes = null; // put your scope like https://www.google.com/m8/feeds/
string accessType = "offline";
string tokenType = "refresh";
OAuth2Parameters parameters = new OAuth2Parameters
{
ClientId = clientId,
ClientSecret = clientSecret,
RedirectUri = redirectUri,
Scope = scopes,
AccessType = accessType,
TokenType = tokenType
};
if (accessCode == null)
{
string url = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters);
// Start webbrowser
Process.Start(url);
// Load code from web via popup, etc.
parameters.AccessCode = accessCodeFromWeb;
}
// Check accessToken and refreshToken
// After first acceess with GetAccessToken you will get that information
if (accessToken == null || refreshToken == null)
{
OAuthUtil.GetAccessToken(parameters);
// Save yours accessToken and refreshToken for next connection
accessToken = parameters.AccessToken;
refreshToken = parameters.RefreshToken;
}
else
{
// Restore your token from config file, etc.
parameters.AccessToken = accessToken;
parameters.RefreshToken = refreshToken;
}
RequestSettings rs = new RequestSettings(applicationName, parameters);
return new ContactsRequest(rs);
関連
-
[解決済み】指定されたキャストが有効でない?
-
[解決済み】プログラム実行中に1秒待つ
-
[解決済み】"The ConnectionString property has not been initialized "を修正する方法
-
[解決済み】リソースの読み込みに失敗した:ステータス500(内部サーバーエラー)のサーバーの応答)
-
[解決済み】aspNetCore 2.2.0 - AspNetCoreModuleV2 エラー
-
[解決済み] [Solved] .NETでスレッドの終了を待つには?
-
[解決済み】Microsoft.Extensions.LoggingからILoggerを解決することができない
-
[解決済み] リクエストの最大長を超えました。
-
[解決済み] HTTP POST Web リクエストの作成方法
-
[解決済み] HttpClientリクエストのContent-Typeヘッダーはどのように設定するのですか?
最新
-
nginxです。[emerg] 0.0.0.0:80 への bind() に失敗しました (98: アドレスは既に使用中です)
-
htmlページでギリシャ文字を使うには
-
ピュアhtml+cssでの要素読み込み効果
-
純粋なhtml + cssで五輪を実現するサンプルコード
-
ナビゲーションバー・ドロップダウンメニューのHTML+CSSサンプルコード
-
タイピング効果を実現するピュアhtml+css
-
htmlの選択ボックスのプレースホルダー作成に関する質問
-
html css3 伸縮しない 画像表示効果
-
トップナビゲーションバーメニュー作成用HTML+CSS
-
html+css 実装 サイバーパンク風ボタン
おすすめ
-
[解決済み】"出力タイプがクラスライブラリのプロジェクトは直接起動できない"
-
[解決済み】C#で四捨五入する方法
-
[解決済み】ASP.NET Core Dependency Injectionのエラーです。アクティブ化しようとしているときに、タイプのサービスを解決できません。
-
[解決済み】統合マネージドパイプラインモードで適用されないASP.NETの設定が検出された
-
[解決済み】C# ASP.NET使用時に「WebClientのリクエスト中に例外が発生しました。
-
[解決済み】「namespace x already contains a definition for x」エラーの修正方法は?VS2010にコンバートした後に発生しました。
-
[解決済み】クロススレッド操作が有効でない。作成されたスレッド以外のスレッドからアクセスされたコントロール
-
[解決済み】Socket.Selectがエラー "An operation was attempted on something that is not a socket" を返す。
-
[解決済み】Moqを使用してメソッド呼び出しを検証する
-
[解決済み】WSACancelBlockingCallの例外について