C# 如何使用RestSharp和oauth2调用googlecloudapi

C# 如何使用RestSharp和oauth2调用googlecloudapi,c#,curl,oauth,restsharp,google-language-api,C#,Curl,Oauth,Restsharp,Google Language Api,我正在尝试调用GoogleCloudAPI。具体来说,c#中的语言API使用RestSharp库和OAuth 2。我能够使用下面的curl调用成功连接到API: curl -s -k -H "Content-Type: application/json" -H "Authorization: Bearer <access_token>" https://language.googleapis.com/v1beta1/documents:annotateText -d @c

我正在尝试调用GoogleCloudAPI。具体来说,c#中的语言API使用RestSharp库和OAuth 2。我能够使用下面的curl调用成功连接到API:

curl -s -k -H "Content-Type: application/json" -H "Authorization: Bearer <access_token>"
     https://language.googleapis.com/v1beta1/documents:annotateText
 -d @c:\temp\entity_request.json > c:\temp\googleanalysis.json
我的问题是如何以我成功使用curl的方式正确地调用RestSharp中的google cloud API?

这对我来说很有用:

            //obtenemos el token para las peticiones
            string access_token = GetAccessToken(jsonFolder, new string[] { "https://www.googleapis.com/auth/cloud-platform" });

            //peticiones hacia el rest de automl
            var client = new RestClient("https://language.googleapis.com");
            var request = new RestRequest("v1/documents:analyzeEntities", Method.POST);

            request.AddHeader("Authorization", string.Format("Bearer {0}", access_token));
            request.AddHeader("Content-Type", "aplication/json");

            //seteamos el objeto
            var aml = new AutoMLload_entities();
            aml.document.content = text;

            request.AddJsonBody(aml);
            IRestResponse response = client.Execute(request);
            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
{
  "error": {
    "code": 403,
    "message": "The request cannot be identified with a client project. Please pass a valid API key with the request.",
    "status": "PERMISSION_DENIED"
  }
}
            //obtenemos el token para las peticiones
            string access_token = GetAccessToken(jsonFolder, new string[] { "https://www.googleapis.com/auth/cloud-platform" });

            //peticiones hacia el rest de automl
            var client = new RestClient("https://language.googleapis.com");
            var request = new RestRequest("v1/documents:analyzeEntities", Method.POST);

            request.AddHeader("Authorization", string.Format("Bearer {0}", access_token));
            request.AddHeader("Content-Type", "aplication/json");

            //seteamos el objeto
            var aml = new AutoMLload_entities();
            aml.document.content = text;

            request.AddJsonBody(aml);
            IRestResponse response = client.Execute(request);
            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {