Sub*_*bbu 40 iphone google-calendar-api ios google-oauth
我正在尝试在IOS应用中授权用户使用Google日历API.我正在使用Google的OAuth2功能对用户进行身份验证.将打开授权页面,其中包含描述403错误:
此用户代理不允许向Google发出OAuth授权请求,因为它被归类为嵌入式用户代理(也称为Web视图).根据我们的政策,只允许浏览器向Google发出授权请求.我们为本机应用提供了几个库和示例,以便在浏览器中执行授权请求.
我按照此链接中提到的相同步骤操作: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";
Run Code Online (Sandbox Code Playgroud)
Dip*_*ama 32
在我的情况下,我使用本地Web视图登录谷歌,我发现你应该为webview提供用户代理的方式它是为我工作的.尝试以下代码我相信它会起作用.
在应用程序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];
Run Code Online (Sandbox Code Playgroud)
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)
Run Code Online (Sandbox Code Playgroud)
小智 15
<preference name="OverrideUserAgent" value="Mozilla/5.0 Google" />
Run Code Online (Sandbox Code Playgroud)
我的cordova项目也面临这个问题.你可以尝试这个:只需将它添加到你的config.xml,为我工作.
如前面的答案所述,这SFSafariViewController是一种方法,但对于那些仍然使用WKWebViewOAuth授权的人来说,有一个简单的解决方法.
只需customUserAgent从列表中更改为一个或将其设置为某个任意值.之后该disallowed_useragent错误将消失:
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration];
// Check for selector availability, as it is available only on iOS 9+
if ([webView respondsToSelector:@selector(setCustomUserAgent:)]) {
webView.customUserAgent = @"MyCustomUserAgent";
}
Run Code Online (Sandbox Code Playgroud)
如需更改User-Agent,UIWebView您可以查看此答案.
但要小心,因为一些后端代码可能依赖于User-Agent标头值.
小智 5
有同样的问题.通过将以下属性设置为webview对象来解决:
webview.getSettings().setUserAgentString("Chrome/56.0.0.0 Mobile");
Run Code Online (Sandbox Code Playgroud)
希望这会有所帮助.
| 归档时间: |
|
| 查看次数: |
67300 次 |
| 最近记录: |