Google.GoogleApiException:'Google.Apis.Requests.RequestError 请求的身份验证范围不足

发布于 2025-01-13 11:48:36 字数 1568 浏览 3 评论 0原文

我正在尝试使用 Google People API 和 C# 创建 google 联系人。我可以列出联系人。但是装箱联系给了我这个异常

Google.GoogleApiException: 'Google.Apis.Requests.RequestError
Request had insufficient authentication scopes. [403]
Errors [
    Message[Insufficient Permission] Location[ - ] Reason[insufficientPermissions] Domain[global]

Fallowing 是该方法的代码

public static void CreateContact()
    {
    string m_client_secret = "LIsZiU972ThMyD7.....";
    string m_client_id = "....n3vgb1o235m.apps.googleusercontent.com";

    UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
            new ClientSecrets
            {
                ClientId = m_client_id,
                ClientSecret = m_client_secret
            },
            new[] { "profile", "https://www.googleapis.com/auth/contacts" },
            "me",
            CancellationToken.None).Result;

        var service = new PeopleServiceService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "ContactCreatorApp",
        });

        var contactToCreate = new Person();
        var names = new List<Name> { new Name() { GivenName = "Jhon", FamilyName = "Doe" } };
        contactToCreate.Names = names;             

        var request = new PeopleResource.CreateContactRequest(service, contactToCreate);
        var createdContact = request.Execute();
}

对我来说它看起来像是范围 new[] { "profile", "https://www.googleapis.com/auth/contacts" 范围内的一些问题}。尝试了多个范围但没有运气。有人有线索吗?

I'm trying to create a google contact using Google People API and C#. I'm able to list the contact . But crating contact gives me this exception

Google.GoogleApiException: 'Google.Apis.Requests.RequestError
Request had insufficient authentication scopes. [403]
Errors [
    Message[Insufficient Permission] Location[ - ] Reason[insufficientPermissions] Domain[global]

Fallowing is the code for the method

public static void CreateContact()
    {
    string m_client_secret = "LIsZiU972ThMyD7.....";
    string m_client_id = "....n3vgb1o235m.apps.googleusercontent.com";

    UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
            new ClientSecrets
            {
                ClientId = m_client_id,
                ClientSecret = m_client_secret
            },
            new[] { "profile", "https://www.googleapis.com/auth/contacts" },
            "me",
            CancellationToken.None).Result;

        var service = new PeopleServiceService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "ContactCreatorApp",
        });

        var contactToCreate = new Person();
        var names = new List<Name> { new Name() { GivenName = "Jhon", FamilyName = "Doe" } };
        contactToCreate.Names = names;             

        var request = new PeopleResource.CreateContactRequest(service, contactToCreate);
        var createdContact = request.Execute();
}

For me It looks like some issue in the scope new[] { "profile", "https://www.googleapis.com/auth/contacts" }. Tried multiple scopes but no luck. Anyone has a clue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文