Receiving forbidden error message (403) when getting the list of beacons in Google Beacon Platform

夙愿已清 提交于 2019-12-12 03:06:30

问题


I have created a service account for my Google Proximity API project and downloaded the key file to use it in my application. But when the very last line of the code snippet below is executed, I receive the following exception:

Google.GoogleApiException was unhandled by user code
HResult=-2146233088 Message=Google.Apis.Requests.RequestError Unauthorized. [403] Errors [ Message[Unauthorized.] Location[ - ] Reason[forbidden] Domain[global]]

And here is the code that is supposed to run on the server machine (backend):

X509Certificate2 certificate = new X509Certificate2(@"key.p12",
                "notasecret", X509KeyStorageFlags.Exportable);

            var credential = new ServiceAccountCredential(
               new ServiceAccountCredential.Initializer("MyServiceId@focal-baton-55555.iam.gserviceaccount.com")
               {
                   Scopes = new[] { "https://www.googleapis.com/auth/userlocation.beacon.registry" },
               }.FromCertificate(certificate));

            var beacon = new Google.Apis.Proximitybeacon.v1beta1.Data.Beacon();

            var beaconServices = new ProximitybeaconService(new BaseClientService.Initializer
            {
                ApplicationName = "My SampleProject",
                HttpClientInitializer = credential 
            });

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

I have spent hours but I could not conclude anything at all. What am I missing in this context and how to fix the problem?


回答1:


I resolved the issue by giving the necessary permissions when creating service account. That was the step that I missed unfortunately. Then I used the same .p12 file to authenticate the application to the API.



来源:https://stackoverflow.com/questions/40705660/receiving-forbidden-error-message-403-when-getting-the-list-of-beacons-in-goog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!