ios - 403 错误 - 这是一个错误。错误 : disallowed_useragent

标签 ios iphone google-calendar-api google-oauth

我正在尝试授权用户在 IOS 应用程序中使用 Google 日历 API。 我正在使用 Google 的 OAuth2 功能来验证用户。授权页面打开时出现 403 错误,描述如下:

This user-agent is not permitted to make OAuth authorisation request to Google as it is classified as an embedded user-agent (also known as a web-view). Per our policy, only browsers are permitted to make authorisation requests to Google. We offer several libraries and samples for native apps to perform authorisation request in browser.

我遵循了此链接中提到的相同程序:https://developers.google.com/google-apps/calendar/quickstart/ios

与其看我的代码,不如看这个链接:https://developers.google.com/google-apps/calendar/quickstart/ios 因为我在我的应用程序中复制粘贴了同样的东西。

下面是我的 clientId 和 keyChainItemName:

static NSString *const kKeychainItemName = @"Google Calendar API";
static NSString *const kClientID = @"954370342601-sgl8k0jrbqdeagea9v6vfu3tspte96ci.apps.googleusercontent.com";

最佳答案

在我的例子中,我使用 native WebView 登录 Google,我发现您应该为 WebView 提供用户代理的方式对我很有效。试试下面的代码,我相信它会起作用。

application didFinishLaunchingWithOptions中添加代码

objective-c

 NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36", @"UserAgent", nil];
 [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];

swift

UserDefaults.standard.register(defaults: ["UserAgent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"])

关于ios - 403 错误 - 这是一个错误。错误 : disallowed_useragent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43053466/

相关文章:

ios - "Onesignal for Voip push"和 "Firebase Cloud Messaging"不能一起工作

ios - 是否所有 iOS 设备都可以在设备上使用 Apple Wallet 应用程序?

ios - UILabel 重绘 View 。如何避免这种行为?

ios - 在objective c中实现RC4加密和URL编码

google-calendar-api - 开发人员控制台上的 Google Calendar Api 错误请求 400 事件

swift - 谷歌 API "Daily Limit for Unauthenticated use Limit"403 错误... iOS

ios - 如何从 NSArray 中选取随机图像并在 View 中随机显示

ios - UICollectionView - 水平排列单元格

ios - 如何在 Swift 中解析 ISO 8601 持续时间格式?

php - Google 日历事件创建和 Google 企业帐户