禁止使用谷歌日历API和C#-403

禁止使用谷歌日历API和C#-403,c#,.net,google-calendar-api,C#,.net,Google Calendar Api,正在寻求帮助。我已经浏览了所有的文档,所以和谷歌,仍然没有运气 我正试图在我的Web应用程序中与Google日历API集成,以实现“检查可用性”功能。目前,我已经掌握了连接的基本知识,我所能做的最远的就是尝试验证和提取一些数据。我已经在下面列出了我的代码-在遵循我看到的所有建议之后,我得到的都是403禁止的错误 谁能看出我哪里出了问题 public void Page_Load(object sender, EventArgs e) { // Register the authenticat

正在寻求帮助。我已经浏览了所有的文档,所以和谷歌,仍然没有运气

我正试图在我的Web应用程序中与Google日历API集成,以实现“检查可用性”功能。目前,我已经掌握了连接的基本知识,我所能做的最远的就是尝试验证和提取一些数据。我已经在下面列出了我的代码-在遵循我看到的所有建议之后,我得到的都是403禁止的错误

谁能看出我哪里出了问题

public void Page_Load(object sender, EventArgs e)
{
  // Register the authenticator. The Client ID and secret have to be copied from the API Access
  // tab on the Google APIs Console.
  var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
  provider.ClientIdentifier = "MY_CLIENT_ID";
  provider.ClientSecret = "MY_SECRET";

  var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthentication);

  // Create the service.
  var service = new CalendarService(new BaseClientService.Initializer
  {
      Authenticator = auth
  });

  EventsResource.ListRequest req = service.Events.List("primary");

  if (req != null)
  {
      var events = req.Fetch();

      if (events != null)
      {
          litResult.Text = events.Items.Count().ToString();
      }
      else
      {
          litResult.Text = "Zilch.";
      }
  }
  else
  {
      litResult.Text = "Nada.";
  }
}

private static IAuthorizationState GetAuthentication(NativeApplicationClient arg)
{
  // Get the auth URL:
  IAuthorizationState state = new AuthorizationState(new[] { "https://www.google.com/calendar/feeds" });
  state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
  Uri authUri = arg.RequestUserAuthorization(state);

  // Request authorization from the user (by opening a browser window):
  Process.Start(authUri.ToString());
  Console.Write("  Authorization Code: ");
  string authCode = Console.ReadLine();
  Console.WriteLine();

  // Retrieve the access token by using the authorization code:
  return arg.ProcessUserAuthorization(authCode, state);
}
public void页面加载(对象发送方,事件参数e)
{
//注册验证器。必须从API访问复制客户端ID和密码
//谷歌API控制台上的标签。
var provider=new NativeApplicationClient(GoogleAuthenticationServer.Description);
provider.ClientIdentifier=“我的客户ID”;
provider.ClientSecret=“我的秘密”;
var auth=新的OAuth2Authenticator(提供者,GetAuthentication);
//创建服务。
var service=new CalendarService(new BaseClientService.Initializer
{
验证器=auth
});
EventsResource.ListRequest req=service.Events.List(“主”);
如果(请求!=null)
{
var events=req.Fetch();
如果(事件!=null)
{
litResult.Text=events.Items.Count().ToString();
}
其他的
{
litResult.Text=“Zilch。”;
}
}
其他的
{
litResult.Text=“Nada。”;
}
}
私有静态IAAuthorizationState GetAuthentication(NativeApplicationClient参数)
{
//获取身份验证URL:
IAAuthorizationState=新授权状态(新[]{”https://www.google.com/calendar/feeds" });
state.Callback=新Uri(NativeApplicationClient.OutOfBandCallbackUrl);
Uri authUri=arg.RequestUserAuthorization(状态);
//请求用户授权(通过打开浏览器窗口):
Process.Start(authUri.ToString());
控制台。写入(“授权代码:”);
字符串authCode=Console.ReadLine();
Console.WriteLine();
//使用授权代码检索访问令牌:
返回参数ProcessUserAuthorization(authCode,state);
}

我想你有:

provider.ClientIdentifier = "MY_CLIENT_ID";
provider.ClientSecret = "MY_SECRET";

你真的需要用页面上给出的客户id和秘密来填写…

谢谢你的智慧之言。。。我最终回到了日历API v2;10分钟后就开始工作了。