Google .NET API因错误403(禁止)而失败 [英] Google .NET API fails due to error 403 (forbidden)

查看:180
本文介绍了Google .NET API因错误403(禁止)而失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码段应该返回信标列表。当Google API控制台生成API密钥时,我已将我的公共IP地址列入白名单并与api密钥关联。当代码调用ExecuteAsync()方法时,我不断收到一个错误代码为403(禁止)的异常。

My code snippet below is supposed to return the list of beacons. When having Google API Console generate an API Key I have whitelisted my public IP address and associated with the api key. When the code calls ExecuteAsync() method, I keep receiving an exception with error code 403 (forbidden). What may have I done wrong and how to mitigate the issue?

public async void TestApiKey()
{
    var apikey = "739479874ABCDEFGH123456"; //it's not the real key I'm using
    var beaconServices = new ProximitybeaconService(new Google.Apis.Services.BaseClientService.Initializer
    {
        ApplicationName = "My Project",
        ApiKey = apikey
    });

    var result = await beaconServices.Beacons.List().ExecuteAsync();

    // Display the results.
    if (result.Beacons != null)
    {
        foreach (var api in result.Beacons)
        {
            Console.WriteLine(api.BeaconName + " - " + api.Status);
        }
    }
}


推荐答案

您正在使用公共API密钥。公共API密钥只适用于公共数据。

You are using a Public API key. Public API keys only work with public data.


beacons.list 使用来自
的OAuth访问令牌对查看者进行身份验证,是拥有者还是可以编辑权限。

beacons.list Authenticate using an OAuth access token from a signed-in user with viewer, Is owner or Can edit permissions.

需要以下OAuth范围:

https://www.googleapis.com/auth/userlocation.beacon.registry

Requires the following OAuth scope:
•https://www.googleapis.com/auth/userlocation.beacon.registry

您尝试的方法访问访问私人用户数据。您需要先进行身份验证才能使用它。切换到Oauth2身份验证。设置为公开可能不会工作,因为你不知道我的知识提供了一个范围公共api键。

The method you are trying to access is accessing private user data. You need to be authentication before you can use it. Switch to Oauth2 authentication. Setting it to public probably wont work because you cant to my knowledge supply a scope to a public api key.

这篇关于Google .NET API因错误403(禁止)而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆