【发布时间】:2018-05-17 07:33:24
【问题描述】:
我按照 PeopleAPI 示例 https://developers.google.com/people/v1/write-people 尝试了 CreateContact,但总是收到错误 403 Insufficient Authentication Scopes。 我已经将范围设置为 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);
}
有什么帮助吗?
TIA
【问题讨论】:
-
我没有使用任何VM,我直接在我的电脑上运行VS
标签: c# api google-people-api