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

查看:2917
本文介绍了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授权请求,因为它是归类为嵌入式用户代理(也称为Web视图)。根据我们的政策,只允许浏览器向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";


推荐答案

在我的情况下,我使用原生网页视图登录通过谷歌,我发现你应该为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];

Swift 3.0

Swift 3.0

let dictionaty = 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: dictionaty)

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

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