Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# PeopleAPI错误403谷歌漏洞与否_C#_Api_Google People - Fatal编程技术网

C# PeopleAPI错误403谷歌漏洞与否

C# PeopleAPI错误403谷歌漏洞与否,c#,api,google-people,C#,Api,Google People,我尝试使用以下PeopleAPI示例创建CreateContact,但始终出现错误403身份验证范围不足。 我已经将范围设置为 PeopleServiceService.Scope.Contacts 下面是我的全部代码 string[] Scopes = new string[] { PeopleServiceService.Scope.Contacts }; UserCredential credential = GoogleWebA

我尝试使用以下PeopleAPI示例创建CreateContact,但始终出现错误403身份验证范围不足。 我已经将范围设置为 PeopleServiceService.Scope.Contacts

下面是我的全部代码

                string[] Scopes = new string[] { PeopleServiceService.Scope.Contacts }; 

            UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
            new ClientSecrets
            {
                ClientId = "xxxxxxx.apps.googleusercontent.com",
                ClientSecret = "xxxxx"
            },
            Scopes,
            "me",
            System.Threading.CancellationToken.None).Result;

         var peopleService = new Google.Apis.PeopleService.v1.PeopleServiceService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "Test1"
        });

        try
        {
            //Create New COntact
            Person contactToCreate = new Person();

            List<Name> names = new List<Name>();
            names.Add(new Name() { GivenName = "a1test1", FamilyName = "zzz" });
            contactToCreate.Names = names;

            Google.Apis.PeopleService.v1.PeopleResource.CreateContactRequest request =
             new Google.Apis.PeopleService.v1.PeopleResource.CreateContactRequest(peopleService, contactToCreate);
            Person createdContact = request.Execute();

        }
        catch (Exception merr)
        {
            MessageBox.Show(merr.Message);                
        }
string[]Scopes=新字符串[]{PeopleServiceService.Scope.Contacts};
UserCredential credential=GoogleWebAuthorizationBroker.AuthorizationAsync(
新客户的秘密
{
ClientId=“xxxxxxx.apps.googleusercontent.com”,
ClientSecret=“xxxxx”
},
范围,
“我”,
System.Threading.CancellationToken.None)结果;
var peopleService=new Google.api.peopleService.v1.PeopleServiceService(new BaseClientService.Initializer())
{
HttpClientInitializer=凭证,
ApplicationName=“Test1”
});
尝试
{
//创建新联系人
Person contactToCreate=新联系人();
列表名称=新列表();
Name.Add(新名称(){GivenName=“a1test1”,FamilyName=“zzz”});
contactToCreate.Names=名称;
Google.API.PeopleService.v1.PeopleResource.CreateContactRequest请求=
新的Google.api.PeopleService.v1.PeopleResource.CreateContactRequest(PeopleService,contactToCreate);
Person createdContact=request.Execute();
}
捕获(异常merr)
{
MessageBox.Show(merr.Message);
}
需要帮忙吗


TIA

这是我的人事服务初始代码

我的呼叫看起来是这样的,但它有更多的代码-无法全部发布:

    public static string[] scopes = { PeopleServiceService.Scope.Contacts };

    GoogleUtils.People people = new People();
    people.InitializePeopleService(scopes, userEmail);
运行InitializePeopleService,然后就可以使用PeopleService了

    using Google.Apis.PeopleService.v1;
    //using Google.Apis.PeopleService.v1.Data;

    public static string[] scopes = { PeopleServiceService.Scope.Contacts };
    private static PeopleServiceService peopleService;

    public void InitializePeopleService(string[] scopes, string impersonateAs, string clientSecretFilePath = "client_secret_svc.json")
    {
        PeopleService = new PeopleServiceService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = Auth.GetServiceAccountAuthorization(scopes: scopes, clientSecretFilePath: clientSecretFilePath, impersonateAs: impersonateAs)
        });

        if (PeopleService.Name != null)
            CurrentPersonEmail = impersonateAs;
        else
        {
            throw new Exception($"Failed to impersonate as {impersonateAs}");
        }
    }

    public static PeopleServiceService PeopleService
    {
        get
        {
            if (peopleService == null)
            {
                throw new Exception("Please initialize the service by calling InitializePeopleService.");
            }

            return peopleService;

        }
        set
        {
            peopleService = value;
        }
    }

有帮助吗?我没有使用任何虚拟机,我直接从我的计算机上运行VS。这是我的身份验证代码