Google.Apis.Requests.RequestError使用Cloud Talent Solution API时,调用方没有权限

时间:2019-03-08 11:55:16

标签: c# google-cloud-talent-solution

我已经在Google云控制台中创建了一个服务帐户并获得了私钥。我正在尝试使用Google Cloud Talent Solution API并创建公司和乔布斯。尝试创建公司时会抛出错误

Google.GoogleApiException:'Google.Apis.Requests.RequestError 呼叫者没有权限[403] 错误[消息[呼叫者没有权限]位置[-]原因[禁止使用域[全局]]'

不确定我在这里想念什么。我还提供了必要的角色和权限(管理员,作业编辑器)。

以下是我的参考源代码。

class Class1
{
    public static GoogleCredential credential;
    public static CloudTalentSolutionService jobServiceClient;
    public static string projectId;
    public static string parent;
    public static Company myCompany;
    public static void Main(string[] args)
    {
        credential = GoogleCredential.GetApplicationDefaultAsync().Result;
        if (credential.IsCreateScopedRequired)
        {
            credential = credential.CreateScoped(new[]
            {
                Google.Apis.CloudTalentSolution.v3.CloudTalentSolutionService.Scope.Jobs
            });
        }
        jobServiceClient = new CloudTalentSolutionService(new BaseClientService.Initializer
        {
            HttpClientInitializer = credential,
            GZipEnabled = false
        });
        projectId = Environment.GetEnvironmentVariable("GOOGLE_CLOUD_PROJECT");
        parent = $"projects/{projectId}";
        myCompany = new Company()
        {
            DisplayName = "SampleCompany",
            HeadquartersAddress = "Address",
            ExternalId = "123456"
        };
        CreateCompanyRequest createCompanyRequest = new CreateCompanyRequest();
        createCompanyRequest.Company = myCompany;
        Company companyCreated = jobServiceClient.Projects.Companies.Create(createCompanyRequest, parent).Execute();
        Console.WriteLine("Created company: " + ToJsonString(companyCreated));
    }
    private static string ToJsonString(object obj)
    {
        return Newtonsoft.Json.JsonConvert.SerializeObject(obj);
    }
}

0 个答案:

没有答案