Google クラウド API を呼び出そうとしています。具体的には、RestSharp ライブラリと OAuth 2 を使用した C# の言語 API です。以下の 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
さまざまな認証方法を試しましたが、これまでのところどれもうまくいきませんでした。私の最新の c# コードは次のようになります。
var client = new RestClient("https://language.googleapis.com");
client.Authenticator = new RestSharp.Authenticators.HttpBasicAuthenticator("client-app", "<access_token>");
var request = new RestRequest("/v1beta1/documents:analyzeEntities", Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddFile("filename", @"c:\temp\entity_request.json");
var response = client.Execute(request);
var content = response.Content;
この呼び出しを c# から実行すると、次のエラーが返されます。
{
"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"
}
}
私の質問は、RestSharp で Google クラウド API を適切に呼び出すにはどうすればよいですか?