403 错误 - 这是一个错误.错误:disallowed_useragent [英] 403 Error - Thats an error. Error: disallowed_useragent

查看:116
本文介绍了403 错误 - 这是一个错误.错误:disallowed_useragent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试授权用户使用 IOS 应用程序中的 Google 日历 API.我正在使用 Google 的 OAuth2 功能对用户进行身份验证.授权页面打开时出现 403 错误,说明如下:

I am trying to authorise a user for Google calendar API inside an IOS app. I am using the OAuth2 feature of Google to authenticate users. Authorisation page opens with a 403 error with the description:

不允许此用户代理向 Google 发出 OAuth 授权请求,因为它被归类为嵌入式用户代理(也称为网络视图).根据我们的政策,只有浏览器才能向 Google 提出授权请求.我们为原生应用提供了多个库和示例,以在浏览器中执行授权请求.

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

I followed the same procedure which is mentioned in this link: https://developers.google.com/google-apps/calendar/quickstart/ios

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

Rather than seeing my code, it's better to look at this link: https://developers.google.com/google-apps/calendar/quickstart/ios because I copy-pasted the same thing in my application.

下面是我的 clientId 和 keyChainItemName:

below are my clientId and keyChainItemName:

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

推荐答案

就我而言,我使用本机 Web 视图登录 Google,我发现您应该向 WebView 提供用户代理的方式对我有用.试试下面的代码,我相信它会起作用.

In my case I was using native web view to login with Google, I find out the way that you should provide user agent to webview it was worked for me. Try below code I am sure it will worked.

应用程序 didFinishLaunchingWithOptions

目标 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];

斯威夫特 3.0

let dictionary = NSDictionary(object: "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36", forKey: "UserAgent" as NSCopying)
UserDefaults.standard.register(defaults: dictionary)

这篇关于403 错误 - 这是一个错误.错误:disallowed_useragent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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