gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 08:13:40 28 4
gpt4 key购买 nike

我正在尝试授权用户在 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com