- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
环境:.net 4.5.1 集成管道上的 ASP.NET 简单 Web 应用程序在服务器 2012 上的 iis8 上运行,不遵循 MVC。
我正在尝试从谷歌的 GoogleWebAuthorizationBroker 获取凭据,但我一直收到“访问被拒绝”...即使我在“授权的 JavaScript 来源”和“授权的重定向 URI”中允许了我的网址
以下已安装应用程序的 URL 实现 https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth#installed-applications
这是我的代码片段
var folder = "F:\\MyApp\\WebApp\\MyGoogleStorage";
string[] scopes = new string[] {
Google.Apis.Proximitybeacon.v1beta1.ProximitybeaconService.Scope.UserlocationBeaconRegistry
};
ClientSecrets secrets = new ClientSecrets()
{
ClientId = CLIENT_ID,
ClientSecret = CLIENT_SECRET
};
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
secrets,
scopes,
"user",
CancellationToken.None,
new FileDataStore(folder)).Result;
并使用另一种方式创建凭据
using (var stream = new FileStream(Utility.AppPath + "/client_secrets.json", FileMode.Open, FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
scopes,
"user", CancellationToken.None, new FileDataStore(folder));
}
但在这两种情况下我都被拒绝访问。
我的假设是,它正在发生,因为我正在尝试使用样本“已安装的应用程序”
请告诉我在 .net 简单 Web 应用程序中最好的方法是什么。
如果有人成功完成,也分享一些代码。
提前致谢..!!!
最佳答案
对于这个解决方案,我发现是
string serviceAccountEmail = "proximitybeacon@proximitytest-1234.iam.gserviceaccount.com"; // Service Account Email
string userEmail = "abc@gmail.com"; //Email of yours
//.p12 file is having all the details about the Service Account we create a Cryptography certificate by it. This you need to download fron your project which you make in Google Developer Console. Foolow stesps from this link https://webapps.stackexchange.com/questions/58411/how-where-to-obtain-a-p12-key-file-from-the-google-developers-console
X509Certificate2 certificate = new X509Certificate2("F://yorrappPath/ProximityTest-2d889bd4fa49.p12", "notasecret", X509KeyStorageFlags.Exportable); // F://yorrappPath -- Give proper location of .p12 file
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
User = userEmail,
Scopes = new string[] { "https://www.googleapis.com/auth/userlocation.beacon.registry" }
}.FromCertificate(certificate));
if (!credential.RequestAccessTokenAsync(CancellationToken.None).Result)
{
return "Can't get the access token";
}
//Beacon Object with its values
Google.Apis.Proximitybeacon.v1beta1.Data.Beacon beacon = new Google.Apis.Proximitybeacon.v1beta1.Data.Beacon();
Google.Apis.Proximitybeacon.v1beta1.Data.AdvertisedId advertisedId = new Google.Apis.Proximitybeacon.v1beta1.Data.AdvertisedId();
beacon.AdvertisedId = new Google.Apis.Proximitybeacon.v1beta1.Data.AdvertisedId() { Id = "ZgCC7BLy8FXla3VmnnibWQ==", Type = "EDDYSTONE" };
beacon.BeaconName = "99911";
beacon.Status = "ACTIVE";
beacon.LatLng = new Google.Apis.Proximitybeacon.v1beta1.Data.LatLng() { Latitude = 28.38, Longitude = 77.12 };
beacon.ExpectedStability = "STABLE";
//Beacon Service for register which having HttpClientInitializer(credential with token detail)
Google.Apis.Proximitybeacon.v1beta1.ProximitybeaconService service = new Google.Apis.Proximitybeacon.v1beta1.ProximitybeaconService(new BaseClientService.Initializer()
{
ApplicationName = "proximityTest", // Replace that with you App name which you given in Google
HttpClientInitializer = credential
});
var registerRequest = new Google.Apis.Proximitybeacon.v1beta1.BeaconsResource.RegisterRequest(service, beacon);
//uncomment this for update beacons. 3 parameter is important for update BeaconName
//var updateRequest = new Google.Apis.Proximitybeacon.v1beta1.BeaconsResource.UpdateRequest(service, beacon, "beacons/3!660082ec12f2f055e56b75669e789b59");
//updateRequest.Execute();
//uncomment this for getting list of beacons.
// var listRequest = new Google.Apis.Proximitybeacon.v1beta1.BeaconsResource.ListRequest(service);
// return listRequest.Execute();
try
{
//This will register a Beacon
registerRequest.Execute();
}
catch (Exception ex)
{
return ex.Message;
}
return beacon;
关于c# - ASP.net Web 应用程序(非 MVC): Accessing Google GoogleWebAuthorizationBroker. AuthorizeAsync 返回拒绝访问错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38981615/
我尝试使用 youtube api v3 和 .NET 将视频上传到 youtube,但它会永远挂起调用 AuthorizeAsync。您还可以在以下位置查看代码:https://developers
GoogleWebAuthorizationBroker.AuthorizeAsync() 在(农场,4.5 NET)暂存服务器上失败,但在本地服务器上运行良好。我已按照帮助热线上的每个代码进行操作,
我们的网站需要从后台代码(asp.net mvc 应用程序)上传视频到youtube。我正在尝试获取 google 凭据,但是当我调用 AuthorizeAsync 时,应用程序只是挂起。我到处寻找解
我有一个 C# .net Web 应用程序,用于将视频上传到 Youtube。这在大约 6 个月前有效,但现在已停止工作。当我在本地计算机上通过 Visual Studio 启动网站时,以下代码挂起:
我正在编写一个 C# 桌面应用程序,可以将其输出复制到用户的 Google 云端硬盘。但是,当我尝试使用 GoogleWebAuthorizationBroker.AuthorizeAsync() 授
问题已更新,以便更好地解释我遇到的问题, 只要我有这个 Controller , [Authorize] public class IdeaManagementController :
我正在尝试更改我们对 .net 客户端库的旧 rest 调用,我有两个相关的问题/问题...... 此页面上的示例应用程序 https://developers.google.com/api-clie
我正在尝试使用 Google Calendar API在我的非 MVC .NET Web 应用程序中。 (这似乎是一个重要的区别。) 我尝试使用来自 this example 的代码在谷歌和 this
我有一个使用 adsense api 的报告应用程序。 我正在使用 GoogleWebAuthorizationBroker.AuthorizeAsync 进行身份验证。 当我在本地使用它时,它工作正
我有一个我编写的 C# 库,它提供了一些辅助函数来访问 Google 云端硬盘。 服务构造函数调用 AuthorizeAsync 如下: // get access token var credent
我在将我的代码发布到 IIS7.0 后遇到 GoogleWebAuthorizationBroker.AuthorizeAsync 超时问题。 通过我的开发环境,一切都按预期工作。我看到了 Googl
我正在尝试使用 Azure 托管 Web 应用程序执行 OAuth2,但我无法使用服务帐户(此处有许多可用的解决方案,但它们都坚持服务帐户/证书),而我需要用户由 Google 进行身份验证和授权。
我正在尝试使用 Azure 托管 Web 应用程序执行 OAuth2,但我无法使用服务帐户(此处有许多可用的解决方案,但它们都坚持服务帐户/证书),而我需要用户由 Google 进行身份验证和授权。
服务器设置: ASP.NET 表单在 .net 4.5.1 集成管道上运行,在服务器 2012 上的 iis8 上运行。 我正在尝试从谷歌的 GoogleWebAuthorizationBroker
当在 Windows 10 桌面/移动设备上运行时,此代码在我的 UWP 应用程序中运行良好,但在 Xbox One 上我收到错误: 我的 C# 代码: credential = await Goog
我在尝试让 MVC5 应用程序在部署时与 Google Mirror API(或与此相关的任何 Google API)一起工作时遇到了一个奇怪的问题。 这是我努力工作的代码: UserCredenti
我正在使用 GoogleWebAuthorizationBroker.AuthorizeAsync() 为 GoogleDrive 授权用户。 它适用于控制台或 UI 应用程序,但如果该方法在 Win
环境:.net 4.5.1 集成管道上的 ASP.NET 简单 Web 应用程序在服务器 2012 上的 iis8 上运行,不遵循 MVC。 我正在尝试从谷歌的 GoogleWebAuthorizat
我正在将 Google token 转换为 json 字符串格式并将该字符串存储在数据库中。 现在在谷歌驱动器中上传文件时,我想在 GoogleWebAuthorizationBroker.Autho
我是一名优秀的程序员,十分优秀!