我有创建联系人并发送请求的方法。调用Execute()
方法后,出现例外。如何正确发送Google联系人中的更改?
private readonly PeopleServiceService _peopleService;
private readonly string[] _scopes = { PeopleServiceService.Scope.Contacts };
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
secrets,
_scopes,
userName,
CancellationToken.None).Result;
_peopleService = new PeopleServiceService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "ApplicationName",
});
var contactToCreate = new Person
{
Names = new List<Name>
{
new Name
{
DisplayName = "John"
}
},
PhoneNumbers = new List<PhoneNumber>
{
new PhoneNumber
{
Value = "+7 777 777 7777"
}
}
};
var request = new PeopleResource.CreateContactRequest(_peopleService, contactToCreate);
request.Execute(); // Exception here
答案 0 :(得分:1)
身份验证范围不足。
您当前没有权限去做您想做的事情。
Method: people.createContact要求具有以下权限范围才能兴奋。
https://www.googleapis.com/auth/contacts
您似乎正在使用它。因此,这里发生了两件事之一。
仔细检查您的代码,确保您使用的是Scope,然后再次尝试登录。