1

Google Calendar API で少し問題が発生しています。カレンダーにイベントを作成しようとしていますが、カレンダー サービスへのクエリがうまくいきません。codeproject で見つけたこのガイド ( Guide ) を使用しており、この認証ガイド ( Authentication Guide ) にリンクしています。認証ガイドの「OAuth 2.0 フロー」のステップ 5 を実行して、アクセス トークンとリフレッシュ トークンを取得できましたが、カレンダー サービスにクエリを実行しようとすると、次のエラーが発生します。

"リクエストの実行に失敗しました: https://www.google.com/calendar/feeds/default/allcalendars/full ", "リモート サーバーがエラーを返しました: (401) Unauthorized."

何が間違っているのかわかりません。ユーザーを承認し、アクセストークンを持っています。だから私は何か小さなものを見逃していると思うでしょうが、私はそれを理解しようとして過去1日間頭を叩いていました.

これは私が使用しているコードです:

        Google.GData.Client.GAuthSubRequestFactory authFactory = new Google.GData.Client.GAuthSubRequestFactory("cl", "API Project");
        authFactory.Token = "ya29...";
        authFactory.KeepAlive = true;
        Google.GData.Calendar.CalendarService service = new CalendarService("API Project");
        service.RequestFactory = authFactory;
        Uri postUri = new Uri(AllCalendarFeed);
        Google.GData.Calendar.CalendarQuery CalendarQuery = new Google.GData.Calendar.CalendarQuery();
        CalendarQuery.Uri = postUri;

        //Errors out on this line:
        Google.GData.Calendar.CalendarFeed calFeed = service.Query(CalendarQuery);

        string CalendarID = "";
        if (calFeed != null && calFeed.Entries.Count > 0)
        {
            foreach (CalendarEntry CalEntry in calFeed.Entries)
            {
                //Commented to post the new appointments 
                //on the main calendar instead of cleverfox calendar
                //if (CalEntry.Title.Text.Contains("Cleverfox") == true)
                //{
                //CalendarID = CalEntry.Title.Text;
                CalendarID = CalEntry.EditUri.ToString().Substring(CalEntry.EditUri.ToString().LastIndexOf("/") + 1);
                break;
                //}
            }
        }

どんな助けでも大歓迎です。ありがとうございました。

4

0 に答える 0